[Bug] Yarn 2 PnP and peer dependencies in Jest tests in workspace
See original GitHub issue- I’d be willing to implement a fix
Describe the bug
Peer dependencies of packages cannot be found when running Jest tests in workspace.
To Reproduce
I have created following minimal setup: https://github.com/kirill-konshin/yarn-berry-bug
Steps to reproduce:
$ git clone https://github.com/kirill-konshin/yarn-berry-bug.git
$ yarn
$ cd ws
$ yarn test
Output:
xxx@xxx ws % yarn test
FAIL src/index.test.js
● Test suite failed to run
Cannot find module 'react' from 'index.js'
However, Jest was able to find:
'./Router.js'
You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].
See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string
at Resolver.resolveModule (../.yarn/cache/jest-resolve-npm-25.1.0-2276a075e4-2.zip/node_modules/jest-resolve/build/index.js:276:11)
at Object.<anonymous> (../.yarn/cache/create-react-class-npm-15.6.3-ae38dfa180-2.zip/node_modules/create-react-class/index.js:11:13)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.293s
Ran all test suites.
It looks like in the following setup require of react-router
causes require of react
in that module which can’t be found. Works perfect without PNP. Adding jest-pnp-resolver does not help.
Environment if relevant (please complete the following information):
- OS: Mac
- Node version: 12.11.1
- Yarn version: 2.0.0-rc.29
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Migration | Yarn - Package Manager
A step-by-step and in-depth migration guide from Yarn 1 (Classic) to Yarn 2 (Berry).
Read more >Newest 'yarn-v2' Questions
My project includes dependency X which in turn has subdependency Y. When I use yarn to start my project I get the error...
Read more >yarn install peer dependencies automatically
A bug. What is the current behavior? After updating jest from 21.2.1 to 22.0.2 yarn install has some problems and causes TeamCity build...
Read more >ts-jest
A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. Latest version: 29.0.3, ...
Read more >pnpm/pnpm - Gitter
readPackage: jest-runner: add jest-environment-jsdom as a peer dependency ... If you are simply trying to symlink two project folders together for testing, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Jest is “lying” and hiding the error that Yarn throws. It becomes very visible if you run your application with
PNP_DEBUG_LEVEL=1
in your environment:As you can see, the true error is:
By looking into the sources for
create-react-class
, we can see that they forgot to list thereact
peer dependency, hence why the resolution fails. Adding apackageExtensions
entry fixes the issue:Done https://github.com/facebook/jest/issues/9594