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

Cannot find module '@babel/traverse' #11590

Closed
happyoliver opened this issue Jun 18, 2021 · 10 comments
Closed

Cannot find module '@babel/traverse' #11590

happyoliver opened this issue Jun 18, 2021 · 10 comments

Comments

@happyoliver
Copy link

🐛 Bug Report

Keep getting "Error: Cannot find module '@babel/traverse'" when running jest.

Original report : kulshekhar/ts-jest#2684

Have installed the required packages and separately installed. @babel/traverse which didn't help either.

To Reproduce

Steps to reproduce the behavior:

if using package.json as belows ( using npm install -D typescript jest ts-jest @types/jest)

{
"devDependencies": {
"@types/jest": "^26.0.23",
"jest": "^27.0.4",
"ts-jest": "^27.0.3",
"typescript": "^4.3.3"
}
}

Expected behavior

run ts-jest

Link to repl or repo (highly encouraged)

https://github.com/bromix/typescript-jest-example

if using the following package.json, it works

"devDependencies": {
"@types/jest": "^26.0.20",
"jest": "^26.6.3",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3"
}

Debug log:

keep getting "Error: Cannot find module '@babel/traverse'" when running jest. node version v12.4.0

Error: Cannot find module '@babel/traverse'
Require stack:

/Users/external-contacts-hub/node_modules/jest-snapshot/build/InlineSnapshots.js
/Users/external-contacts-hub/node_modules/jest-snapshot/build/State.js
/Users//external-contacts-hub/node_modules/jest-snapshot/build/index.js
/Users/external-contacts-hub/node_modules/jest-runtime/build/index.js
/Users/external-contacts-hub/node_modules/@jest/core/build/cli/index.js
/Users/external-contacts-hub/node_modules/@jest/core/build/jest.js
/Users/external-contacts-hub/node_modules/jest/node_modules/jest-cli/build/cli/index.js
/Users/external-contacts-hub/node_modules/jest/node_modules/jest-cli/bin/jest.js
/Users/external-contacts-hub/node_modules/jest/bin/jest.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
at Function.resolve (internal/modules/cjs/helpers.js:21:19)
at Object. (/Users/external-contacts-hub/node_modules/jest-snapshot/build/InlineSnapshots.js:72:17)
at Module._compile (internal/modules/cjs/loader.js:774:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
at Module.load (internal/modules/cjs/loader.js:641:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:681:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object. (/Users/external-contacts-hub/node_modules/jest-snapshot/build/State.js:13:24)

envinfo

System:
OS: MacOs Big Sur Version 11.3.1
Node version: v12.4.0

Npm packages:
jest:
ts-jest:
typescript:
babel(optional):


@ubansi
Copy link

ubansi commented Jun 22, 2021

自分もnode v12.4.0で実行した場合同じ現象が発生しました。
nodeのバージョンをv14.17.1にアップデートした結果
問題は解決しました。

I had the same problem when running on node v12.4.0.
As a result of updating the node version to v14.17.1
The problem has been solved.

@SimenB
Copy link
Member

SimenB commented Jun 22, 2021

Please provide a minimal reproduction without using typescript or ts-jest

@sdkawata
Copy link

sdkawata commented Jul 1, 2021

I had the same problem.
Here is a minimal reproduction without typescript and ts-jest.
https://github.com/sdkawata/11590

$ npx jest
Error: Cannot find module '@babel/traverse'
Require stack:
- /Users/kawata/11590/node_modules/jest-snapshot/build/InlineSnapshots.js
- /Users/kawata/11590/node_modules/jest-snapshot/build/State.js
- /Users/kawata/11590/node_modules/jest-snapshot/build/index.js
- /Users/kawata/11590/node_modules/jest-runtime/build/index.js
- /Users/kawata/11590/node_modules/@jest/core/build/cli/index.js
- /Users/kawata/11590/node_modules/@jest/core/build/jest.js
- /Users/kawata/11590/node_modules/jest/node_modules/jest-cli/build/cli/index.js
- /Users/kawata/11590/node_modules/jest/node_modules/jest-cli/bin/jest.js
- /Users/kawata/11590/node_modules/jest/bin/jest.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
    at Function.resolve (internal/modules/cjs/helpers.js:21:19)
    at Object.<anonymous> (/Users/kawata/11590/node_modules/jest-snapshot/build/InlineSnapshots.js:146:17)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:681:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/Users/kawata/11590/node_modules/jest-snapshot/build/State.js:27:24)

tested in
OS: MacOs Catalina Version 10.15.7
Node version: v12.4.0

this problem does NOT occur in node v14.17.1 and v12.22.1

@asthemus
Copy link

Have been getting the same error with given config

{
"devDependencies": {
"@types/jest": "^26.0.23",
"jest": "^27.0.4",
"ts-jest": "^27.0.3",
"typescript": "4.2.3"
}
}

System:
OS: macOS 10.15.7
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
Node: 14.15.0 - /usr/local/bin/node

@Hayashi-Yudai
Copy link

I have the same problem.

  • Ubuntu 20.04
  • npm@7.24.0
  • jest 27.2.1

The package I installed is only jest (and its dependencies).

npm test

> scan_system@1.0.0 test
> jest

Error: Cannot find module '@babel/traverse'
Require stack:
- /home/yudai/scan_system/node_modules/jest-snapshot/build/InlineSnapshots.js
- /home/yudai/scan_system/node_modules/jest-snapshot/build/State.js
- /home/yudai/scan_system/node_modules/jest-snapshot/build/index.js
- /home/yudai/scan_system/node_modules/jest-runtime/build/index.js
- /home/yudai/scan_system/node_modules/@jest/core/build/cli/index.js
- /home/yudai/scan_system/node_modules/@jest/core/build/jest.js
- /home/yudai/scan_system/node_modules/jest-cli/build/cli/index.js
- /home/yudai/scan_system/node_modules/jest-cli/bin/jest.js
- /home/yudai/scan_system/node_modules/jest/bin/jest.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
    at Function.resolve (internal/modules/cjs/helpers.js:21:19)
    at Object.<anonymous> (/home/yudai/Dropbox/takahashi_lab/data/rapid_scan/scan_system/node_modules/jest-snapshot/build/InlineSnapshots.js:146:17)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:681:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/home/yudai/Dropbox/takahashi_lab/data/rapid_scan/scan_system/node_modules/jest-snapshot/build/State.js:27:24)

After down grading jest to 26.6.3, the problem was also resolved.

@BuggMaker
Copy link

BuggMaker commented Nov 12, 2021

same issue with node v12; switch node to v15 and reinstall node_module, problem solved

@SimenB
Copy link
Member

SimenB commented Nov 12, 2021

Thanks for the reproduction @sdkawata, sorry I missed it!

Node version: v12.4.0
this problem does NOT occur in node v14.17.1 and v12.22.1

Minimum supported node version (of v12) is 12.13: https://github.com/facebook/jest/blob/42b020f2931ac04820521cc8037b7c430eb2fa2f/package.json#L148, so if the issue is only with 12.4 we can close this.

Can anyone provide a reproduction using a supported version of node?


Note that jest-snapshot does have a dependency on @babel/traverse, so this is more than likely a bug in your package manager than in Jest: https://github.com/facebook/jest/blob/42b020f2931ac04820521cc8037b7c430eb2fa2f/packages/jest-snapshot/package.json#L21

@sdkawata
Copy link

Thank you for the reply.

Minimum supported node version (of v12) is 12.13:

Sorry for not checking minimum supported version.

I checked my reproduction in node v12.13.0, v14.15.0, v15.0.0, and confirmed that the problem does not occur in node v12.13.0, v14.15.0, v15.0.0.

I dig into this error, and find that error throw from require.resolve function in requireOutside function defined here.
https://github.com/facebook/jest/blob/bc50e7f360ab1845abbaa0b3ad788caead0d3174/scripts/babel-plugin-jest-require-outside-vm.js#L27-L31
This is because require.resolve() fails to resolve path if options without path given in node v12.4.0.
This issue fixed in nodejs/node#28078.

Welcome to Node.js v12.5.0.
Type ".help" for more information.
> require.resolve('@babel/traverse', {[Symbol('foobar')]:true})
'/home/kawata/11590/node_modules/@babel/traverse/lib/index.js'
Welcome to Node.js v12.4.0.
Type ".help" for more information.
> require.resolve('@babel/traverse', {[Symbol('foobar')]:true})
Thrown:
Error: Cannot find module '@babel/traverse'
Require stack:
- <repl>
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
    at Function.resolve (internal/modules/cjs/helpers.js:21:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '<repl>' ]]

So, I think we can close this issue because this problem may not occur in supported node version.

@SimenB
Copy link
Member

SimenB commented Nov 23, 2021

Great, thanks for digging into the root cause @sdkawata!

@SimenB SimenB closed this as completed Nov 23, 2021
@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 Dec 24, 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

7 participants