jest
jest copied to clipboard
[Bug]: Module cache already has entry - /node_modules/yargs/build/lib/parse-command.js.
Version
28.1.2
Steps to reproduce
- Clone https://github.com/bameyrick/iso-3166-1-flags-sprite-generator.git
- Checkout branch
yargs - Run
npm i - Run
npm run fetch - Run
npm run test - Tests will fail with the error:
Module cache already has entry /iso-3166-1-flags-sprite-generator/node_modules/yargs/build/lib/parse-command.js. This is a bug in Jest, please report it!
at invariant (node_modules/jest-runtime/build/index.js:2591:11)
at async Promise.all (index 4)
at async Promise.all (index 5)
Expected behavior
Jest should be able to run both sets of tests
Actual behavior
Module cache already has entry /iso-3166-1-flags-sprite-generator/node_modules/yargs/build/lib/parse-command.js. This is a bug in Jest, please report it! error thrown
Additional context
No response
Environment
System:
OS: macOS 12.4
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v16.15.1/bin/yarn
npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
npmPackages:
jest: ^28.1.2 => 28.1.2
I don't quite understand what's going on, but I was able to replicate this on my machine.
System:
OS: Windows 10 10.0.19043 Build 19043
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
npm: 8.5.05- ~/.nvm/versions/node/v8.5.5/bin/npm
npmPackages:
jest: ^28.1.2 => 28.1.2
I'm getting the same error:
Module cache already has entry .../got/dist/source/index.js. This is a bug in Jest, please report it!
I think it's related to dynamic imports:
const gotPromise = import('got')
Update: The error went away by moving the dynamic import away from the root of the file, and into the code that uses the import:
(await import('got')).got.get(...)
however now the whole test suite hangs forever
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
@bameyrick sorry, missed this one! I get an error when trying to run npm run fetch
$ npm run fetch
> [email protected] fetch
> ts-node src/fetch.ts
(node:11581) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/simen/repos/iso-3166-1-flags-sprite-generator/src/fetch.ts:1
import fetch from 'node-fetch';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1055:15)
at Module._compile (node:internal/modules/cjs/loader:1090:27)
at Module.m._compile (/Users/simen/repos/iso-3166-1-flags-sprite-generator/node_modules/ts-node/src/index.ts:1597:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Object.require.extensions.<computed> [as .ts] (/Users/simen/repos/iso-3166-1-flags-sprite-generator/node_modules/ts-node/src/index.ts:1600:12)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at phase4 (/Users/simen/repos/iso-3166-1-flags-sprite-generator/node_modules/ts-node/src/bin.ts:579:12)
Never mind, seems like the step is not needed - I can reproduce 👍
https://github.com/facebook/jest/releases/tag/v29.0.2
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.