question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: jest fails when @cspot/source-map-support and yarn 2+ pnp are involved.

See original GitHub issue

Version

27.5.1

Steps to reproduce

Use this repo: https://github.com/noahnu/repro-source-map-error (h/t @noahnu for making this)

  1. yarn install
  2. 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:

https://github.com/facebook/jest/blob/3a85065fe5604655e1337ffc1631f9999722c821/packages/jest-runner/src/runTest.ts#L213-L219

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Methuselah96commented, Mar 4, 2022

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:

packageExtensions:
  '@cspotcode/source-map-support@*':
    dependencies:
      source-map-support: '*'
2reactions
francisucommented, Feb 11, 2022

ideally with some integration test that fails without the change. Possibly just the reproduction used in the OP

Naturally

Read more comments on GitHub >

github_iconTop Results From Across the Web

jest-environment-jsdom | Yarn - Package Manager
Fixed support for running Jest as a git submodule. ... Fixed test runtime error reporting and stack traces. Improved toBeCalled Jasmine 2 custom...
Read more >
How to debug Jest Tests when using Yarn 2 / Yarn PnP
I was able to run our jest tests using node and some debugging flag helpers (in a Yarn pnp context) using this command:...
Read more >
Getting Started - Jest
Note: Jest documentation uses yarn commands, but npm will also work. You can compare yarn and npm commands in the yarn docs, here....
Read more >
Error cannot find module */jest-intellij-stdin-fix.js when using ...
Error cannot find module */jest-intellij-stdin-fix.js when using Yarn 3 pnp · 1. Install Nodejs version 16.14.0 · 2. Enable corepack via corepack ...
Read more >
除错 - Yarn 中文文档
This error simply means that the specified package is requiring something ... require(`jest-environment-${config.environment}`) - in this circumstances the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found