Skip to content

Yarn PNP errors are swallowed by Jest which makes debugging quite hard #9594

Closed
@kirill-konshin

Description

@kirill-konshin

Original issue: yarnpkg/berry#943

In short, if some package has unlisted peer dependency, Jest will emit something like this (in this case it was react-router@3 and it's underlying package create-react-class:

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.

As you see, there is no information to trace the error.

True error looks like this (PNP_DEBUG_LEVEL=1 was set in environment):

image

As you can see, the true error is:

error: Error: A package is trying to access another package without the second one being listed as a dependency of the first one

Required package: react (via "react")
Required by: create-react-class@npm:15.6.3 (via /home/arcanis/yarn-berry-bug/.yarn/cache/create-react-class-npm-15.6.3-ae38dfa180-2.zip/node_modules/create-react-class/)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions