[Bug?]: TypeError: (0 , _flags.default) is not a function - probably pnp (corejs and jest) related
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 8.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Self-service
- I'd be willing to implement a fix
Describe the bug
I started experiencing this TypeError: (0 , _flags.default) is not a function error after I did an update to one of our react projects, and it only happens when I try to run tests with jest. I have created two repos where the bug can be reproduced. After reading some info I think this might be related to these issues (but I'm not 100% sure)
https://github.com/yarnpkg/berry/issues/3708
https://github.com/yarnpkg/berry/issues/4045
To reproduce
The first repo where this can be reproduced
https://github.com/smooth-organization/jest-error-4
Steps that are needed in order to get the error:
- Clone the repo (no need to "yarn install" because of zero installs)
- 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.
- Clear the resolutions field (which was added in order to use the specific versions of several packages) in the package.json file and "yarn install". After that there should be several updates in the cache folder:

- Run both tests again. The simple one should remain unchanged, but the react one should throw the error:

The second repo where the error is present
https://github.com/smooth-organization/jest-error
You need to run yarn run test-react
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)
The issue is present on both Windows and WSL.
Environment
System:
OS: Windows 10 10.0.22621
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Binaries:
Node: 18.14.0 - ...\AppData\Local\Temp\xfs-03ecf1c2\node.CMD
Yarn: 3.1.0 - ...\AppData\Local\Temp\xfs-03ecf1c2\yarn.CMD
npm: 9.3.1 - ...\nodejs\npm.CMD
OR
System:
OS: Linux 5.10 Ubuntu 20.04.4 LTS (Focal Fossa)
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Binaries:
Node: 18.1.0 - /tmp/xfs-f3006aa2/node
Yarn: 3.1.0 - /tmp/xfs-f3006aa2/yarn
npm: 8.8.0 - ~/.nvm/versions/node/v18.1.0/bin/npm
Additional context
I also reported the bug to the core-js author https://github.com/zloirock/core-js/issues/1183 but it seems like it's not related to that package.
I tried updating to yarn 4 (rc), corejs 3.29.1 or jest 29 but the error persists.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Clone smooth-organization/jest-error-4 and smooth-organization/jest-error, then run the documented yarn test-simple and yarn test-react commands. Compare package.json with and without the resolutions field and inspect src/react-test.spec.js alongside the reported core-js-pure and React stack frames. Done means the React test no longer raises the TypeError after dependency installation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, react, typescript
- Domain
- developer-experience, testing-qa, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100