shouldn't resolve internalModule according to "moduleNameMapper" in jest.config.js
See original GitHub issueš Bug Report
// jest.config.js
moduleNameMapper: {
'Utils': '<rootDir>/src/utils',
}
Runing my tests always fail, saying SyntaxError: Unexpected token 'export'
.
It take my a long time to try various solutions since that misleading error message (I even write a custom ts transformer)
Until the end, I dived into the error stack and found that:
// requireModule method
modulePath = this._resolveModule(from, moduleName);
// from: '/Users/justin/myproject/node_modules/expect/build/asymmetricMatchers.js'
// moduleName './jasmineUtils'
// => '/Users/justin/myproject/src/utils/index.ts' !!!!!
Expected behavior
Never use jest config when resolve internalModule
Envinfo
System:
OS: macOS Mojave 10.14.6
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 12.16.3 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.5 - /usr/local/bin/npm
npmPackages:
jest: 26.6.3 => 26.6.3
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
`moduleNameMapper` settings in jest.config.js doesn't work ...
According to this issue, I use tsconfig-paths and tsconfig-paths-jest . So my setting-files have changed like below. tsconfig.json. { "Ā ...
Read more >Configuring Jest
It is recommended to define the configuration in a dedicated JavaScript, TypeScript or JSON file. The file will be discovered automatically, if it...
Read more >module-alias-jest - npm
module-alias-jest enables you to setup your module aliases in one place (e.g. your package.json), then use them in both jest tests and elsewhereĀ ......
Read more >Pup - jest.config.js | Clever Beagle
The modulePaths property tells Jest where it can resolve NPM modules used inside of the code you're testing. This is utilized for mocking...
Read more >jest-circus | Yarn - Package Manager
jest -circus. The next-gen test runner for Jest ... Performance. 29.3.1. Fixes. [jest-config] Do not warn about preset in ProjectConfig #13583Ā ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is definitely a bug. Another example with Lodash:
Iām replacing
lodash
withlodash-es
same as I do in my Webpack config. Seems like Jest use Lodash on its own, but this Lodash doesnāt go through the transformer (babel-jest):I have other packages in
node_modules
that are ESM and they do get transformed if I comment out Lodash. Either doesnāt run internal modules trough the mapper or apply transformers to them too. Maybe @SimenB could help to triage.i met the same problem with lodash, have you fixed this problem?