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

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

Closed
kirill-konshin opened this issue Feb 18, 2020 · 5 comments
Closed

Comments

@kirill-konshin
Copy link

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/)
@SimenB
Copy link
Member

SimenB commented Feb 19, 2020

Thanks! In addition to surfacing that message about missing declared dependencies, we should also construct a requireStack similar to what node and yarn does and print that. We can keep track of the requireStack in jest-runtime.

@MarcoScabbiolo
Copy link
Contributor

@SimenB mind if I take this one? I've been digging into the source code and I have an idea of how to implement this, and a e2e test in place for it.

@SimenB
Copy link
Member

SimenB commented Mar 16, 2020

Please do!

@thymikee
Copy link
Collaborator

Closed via #9681

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants