Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: (0 , _flags.default) is not a function #1183

Open
smooth-man opened this issue Feb 14, 2023 · 5 comments
Open

TypeError: (0 , _flags.default) is not a function #1183

smooth-man opened this issue Feb 14, 2023 · 5 comments

Comments

@smooth-man
Copy link

Greetings!

I have a react project that runs on yarn with nodeLinker: "pnp" (zero installs), and I'm getting the following error when I try to run tests:

TypeError: (0 , _flags.default) is not a function

> 1 | import '@testing-library/jest-dom/extend-expect'
    | ^
  2 |

  at flags (.yarn/cache/core-js-pure-npm-3.28.0-172396ba34-8bef96a435.zip/node_modules/core-js-pure/internals/regexp-get-flags.js:9:12)
  at Object.<anonymous>.module.exports (.yarn/cache/core-js-pure-npm-3.28.0-172396ba34-8bef96a435.zip/node_modules/core-js-pure/es/instance/flags.js:7:75)
  at getPolyfill (.yarn/cache/regexp.prototype.flags-npm-1.4.3-df1c08b65d-51228bae73.zip/node_modules/regexp.prototype.flags/polyfill.js:9:29)
  at Object.<anonymous> (.yarn/cache/regexp.prototype.flags-npm-1.4.3-df1c08b65d-51228bae73.zip/node_modules/regexp.prototype.flags/index.js:10:27)
  at Object.<anonymous> (.yarn/cache/deep-equal-npm-2.2.0-d9712e0040-46a34509d2.zip/node_modules/deep-equal/index.js:5:13)
  at Object.<anonymous> (.yarn/cache/aria-query-npm-5.1.3-9632eccdee-929ff95f02.zip/node_modules/aria-query/lib/elementRoleMap.js:7:41)
  at Object.<anonymous> (.yarn/cache/aria-query-npm-5.1.3-9632eccdee-929ff95f02.zip/node_modules/aria-query/lib/index.js:10:46)
  at Object.<anonymous> (src/test/setup.js:1:1)

I'm using react 18.2.0, @testing-library/react 13.4.0 and @testing-library/jest-dom 5.16.5. I really can't provide any more details and I understand that this might not be enough for anything and that this might not be related to core-js at all, I'm just wondering has anyone else experienced similar issue? Thanks in advance and I apologize for the scarce information.

The issue is not present when I set the nodeLinker to node_modules, which is when yarn uses the node_modules folder approach to handle packages.

@zloirock
Copy link
Owner

zloirock commented Feb 14, 2023

It can be a conflict with regexp.prototype.flags package - different polyfills are not recommended to use together.

Please, add a reproducible example, without it I can't say more.

@smooth-man
Copy link
Author

smooth-man commented Feb 16, 2023

I have made a repo where the error can be reproduced (hopefully):

https://github.com/smooth-organization/jest-error

Clone, yarn install and yarn run test-react.
Running it on node 18.4 and yarn 3.1.0 (zero installs) (tested on 3.4.1 but error is still present).

I've added two tests in the provided example - one simple and one with react rendering. The simple tests used to break because of the 5.1.3 version of the aria-query package.

TypeError: (0 , _flags.default) is not a function

> 1 | import '@testing-library/jest-dom/extend-expect'
    | ^
  2 |

  at Object.<anonymous>.module.exports (.yarn/cache/core-js-pure-npm-3.28.0-172396ba34-8bef96a435.zip/node_modules/core-js-pure/internals/regexp-get-flags.js:9:12)
  at flags (.yarn/cache/core-js-pure-npm-3.28.0-172396ba34-8bef96a435.zip/node_modules/core-js-pure/es/instance/flags.js:7:75)
  at getPolyfill (.yarn/cache/regexp.prototype.flags-npm-1.4.3-df1c08b65d-51228bae73.zip/node_modules/regexp.prototype.flags/polyfill.js:9:29)
  at Object.getPolyfill (.yarn/cache/regexp.prototype.flags-npm-1.4.3-df1c08b65d-51228bae73.zip/node_modules/regexp.prototype.flags/index.js:10:27)
  at Object.require (.yarn/cache/deep-equal-npm-2.2.0-d9712e0040-46a34509d2.zip/node_modules/deep-equal/index.js:5:13)
  at Object.require (.yarn/cache/aria-query-npm-5.1.3-9632eccdee-929ff95f02.zip/node_modules/aria-query/lib/elementRoleMap.js:7:41)
  at Object.require (.yarn/cache/aria-query-npm-5.1.3-9632eccdee-929ff95f02.zip/node_modules/aria-query/lib/index.js:10:46)
  at Object.<anonymous> (src/test/setup.js:1:1)

I added the resolution field in the package.json file so that the project only uses the 5.0.0 version. With that done the simple test runs fine, but the react rendering one fails:

TypeError: (0 , _flags.default) is not a function

  4 | describe("react test", () => {
  5 |       it("should work", () => {
> 6 |               const { getByText } = render(<App />)
    |                                           ^
  7 |               expect(getByText('this is my app')).toBeTruthy()
  8 |       });
  9 | });

  at Object.<anonymous>.module.exports (.yarn/cache/core-js-pure-npm-3.28.0-172396ba34-8bef96a435.zip/node_modules/core-js-pure/es/instance/flags.js:7:84)
  at getNearestMountedFiber (.yarn/__virtual__/react-dom-virtual-97896247fb/0/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip/node_modules/react-dom/cjs/react-dom.development.js:4463:12)
  at getNearestMountedFiber (.yarn/__virtual__/react-dom-virtual-97896247fb/0/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip/node_modules/react-dom/cjs/react-dom.development.js:4549:26)
  at findCurrentFiberUsingSlowPath (.yarn/__virtual__/react-dom-virtual-97896247fb/0/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip/node_modules/react-dom/cjs/react-dom.development.js:4729:23)
  at findCurrentHostFiberWithNoPortals (.yarn/__virtual__/react-dom-virtual-97896247fb/0/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip/node_modules/react-dom/cjs/react-dom.development.js:28968:19)
  at ReactDOMRoot.findHostInstanceWithNoPortals [as render] (.yarn/__virtual__/react-dom-virtual-97896247fb/0/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip/node_modules/react-dom/cjs/react-dom.development.js:29304:26)
  at Object.render (.yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/pure.js:122:12)
  at render (.yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/pure.js:163:12)
  at callback (.yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/act-compat.js:64:24)
  at callback (.yarn/cache/react-npm-18.2.0-1eae08fee2-88e38092da.zip/node_modules/react/cjs/react.development.js:2512:16)
  at actImplementation (.yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/act-compat.js:63:25) 
  at renderRoot (.yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/pure.js:159:25)
  at renderRoot (.yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/pure.js:246:10)
  at Object.<anonymous> (src/react-test.spec.js:6:31)

  at Object.<anonymous>.module.exports (.yarn/cache/core-js-pure-npm-3.28.0-172396ba34-8bef96a435.zip/node_modules/core-js-pure/es/instance/flags.js:7:84)
  at markUpdateLaneFromFiberToRoot (.yarn/__virtual__/react-dom-virtual-97896247fb/0/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip/node_modules/react-dom/cjs/react-dom.development.js:13395:32)
  at markUpdateLaneFromFiberToRoot (.yarn/__virtual__/react-dom-virtual-97896247fb/0/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip/node_modules/react-dom/cjs/react-dom.development.js:13376:10)
  at enqueueConcurrentClassUpdate (.yarn/__virtual__/react-dom-virtual-97896247fb/0/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip/node_modules/react-dom/cjs/react-dom.development.js:13525:12)
  at enqueueUpdate (.yarn/__virtual__/react-dom-virtual-97896247fb/0/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip/node_modules/react-dom/cjs/react-dom.development.js:28855:14)
  at updateContainer (.yarn/__virtual__/react-dom-virtual-97896247fb/0/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip/node_modules/react-dom/cjs/react-dom.development.js:29337:7)
  at fn (.yarn/__virtual__/react-dom-virtual-97896247fb/0/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip/node_modules/react-dom/cjs/react-dom.development.js:26189:14)
  at ReactDOMRoot.flushSync [as unmount] (.yarn/__virtual__/react-dom-virtual-97896247fb/0/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip/node_modules/react-dom/cjs/react-dom.development.js:29336:5)
  at Object.unmount (.yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/pure.js:126:12)
  at unmount (.yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/pure.js:262:12)
  at callback (.yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/act-compat.js:64:24)
  at callback (.yarn/cache/react-npm-18.2.0-1eae08fee2-88e38092da.zip/node_modules/react/cjs/react.development.js:2512:16)
  at actImplementation (.yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/act-compat.js:63:25) 
  at .yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/pure.js:261:27
      at Array.forEach (<anonymous>)
  at forEach (.yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/pure.js:257:22)
  at Object.<anonymous> (.yarn/__virtual__/@testing-library-react-virtual-e9e4b497e1/0/cache/@testing-library-react-npm-13.4.0-eaa652c0f5-51ec548c1f.zip/node_modules/@testing-library/react/dist/index.js:35:24)

@zloirock
Copy link
Owner

Thanks, I was able to reproduce it. It's hard to understand the reason - it still looks like a conflict. I need time to dig it out.

@smooth-man
Copy link
Author

Thanks. I've been doing some investigating myself. I have a branch where I use the following resolutions and everything works:

"core-js-compat": "3.20.2",
"browserslist": "4.19.1",
"minimatch": "3.1.2",
"caniuse-lite": "1.0.30001397",
"dom-accessibility-api": "0.5.10"

I wish I can dig deeper into this but I have a lot of work atm. I'll post updates when I can!

@smooth-man
Copy link
Author

Right!
So here is another repo with older versions of most of the dependencies https://github.com/smooth-organization/jest-error-4

These are the steps that are needed in order to get the error:

  1. Clone the repo (no need to "yarn install" because of zero installs)
  2. Run both tests "yarn run test-simple" and "yarn run test-react" - they are setup in such a way that both files contain two tests - one should work, one should fail. When tests are run for the first time, you should get a lot of "Internal error in the corejs3 provider: unknown polyfill" warnings, but for the time being this is fine.
  3. Clear the resolutions field in the package.json file and "yarn install". After that there should be several updates in the cache folder:
    image
  4. Run both tests again. The simple one should remain unchanged, but the react one should throw the error:
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants