jest: [Bug]: jest fails when @cspot/source-map-support and yarn 2+ pnp are involved.
Version
27.5.1
Steps to reproduce
Use this repo: https://github.com/noahnu/repro-source-map-error (h/t @noahnu for making this)
yarn install
yarn ts-node --transpile-only $(yarn bin jest)
Expected behavior
Test should pass.
Actual behavior
% yarn ts-node --transpile-only $(yarn bin jest)
FAIL ./index.test.ts
● Test suite failed to run
Cannot find module 'source-map-support' from '/Users/francis/temp/repro-source-map-error/.yarn/cache/@cspotcode-source-map-support-npm-0.7.0-456c3ea2ce-9faddda775.zip/node_modules/@cspotcode/source-map-support'
at resolveSync (.yarn/cache/resolve-patch-bad885c6ea-c79ecaea36.zip/node_modules/resolve/lib/sync.js:111:15)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.132 s
Ran all test suites.
Additional context
The original issue is: https://github.com/cspotcode/node-source-map-support/issues/35, but it seems to be a Jest problem.
Here is the a patch that fixes it (thanks to @cspotcode )
Replace this code:
with:
const resolved = require.resolve('source-map-support');
runtime.requireInternalModule(resolved, resolved).install(sourcemapOptions);
This might be related to:
https://github.com/facebook/jest/issues/8930 https://github.com/facebook/jest/issues/11453
Environment
System:
OS: macOS 12.1
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
Node: 14.17.3 - ~/.nvm/versions/node/v14.17.3/bin/node
Yarn: 3.1.1 - /usr/local/bin/yarn
npm: 8.1.0 - ~/.nvm/versions/node/v14.17.3/bin/npm
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 17 (12 by maintainers)
Interestingly enough I had this error in CI (Ubuntu), but it worked fine locally (Windows). Added this to my
.yarnrc.yml
while waiting for this to get fixed:Naturally