jest: jest-haste-map: TypeError: dupMap.get is not a function
🐛 Bug Report
Running a jest test results in a test build failure:
TypeError: dupMap.get is not a function
at ModuleMap._getModuleMetadata (node_modules/jest-haste-map/build/ModuleMap.js:231:14)
When console logging dupMap
at the source location, dupMap
is undefined. I don’t see a control flow where this is possible because when dupMap is declared, it is set to EMPTY_MAP if it’s value would be undefined.
The error is also bound to a material-ui style object, which doesn’t make much sense.
To Reproduce
Steps to reproduce the behavior:
I’m afraid I don’t have a reproduction. I’m using lerna
and material-ui
in jest. The library I’m experiencing the issue with is dependent on another library in my mono repo.
Expected behavior
The test runs without problems
Link to repl or repo (highly encouraged)
Unavailable, sorry
envinfo
System:
OS: Linux 5.0 Ubuntu 18.04.2 LTS (Bionic Beaver)
CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
Binaries:
Node: 10.16.0 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
npmPackages:
jest: ^24.9.0 => 24.9.0
My jest config:
"jest": {
"collectCoverageFrom": [
"packages/**/*.{js,jsx,mjs}",
"!packages/**/common/icons/components/*",
"!packages/**/*.stories.{js,jsx,ts,tsx}",
"!packages/**/**/story/**/*.{js,jsx,ts,tsx}"
],
"moduleDirectories": [
"node_modules"
],
"setupFilesAfterEnv": [
"<rootDir>/config/jest/setup.js"
],
"setupFiles": [
"<rootDir>/config/polyfills.js"
],
"testMatch": [
"<rootDir>/packages/**/?(*.)(spec|test).{js,jsx,mjs}"
],
"testEnvironment": "jsdom",
"testURL": "http://localhost",
"transform": {
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
],
"moduleFileExtensions": [
"web.js",
"js",
"json",
"web.jsx",
"jsx",
"node",
"mjs",
"ts",
"tsx"
]
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 10
- Comments: 40 (9 by maintainers)
I was able to get rid of this error by calling jest --clearCache, probably because I had fixed one of the other causes listed above, but the cache retained the error?
I ran into this same issue today. For me the issue was related to using yalc to develop multiple dependent repos.
The problem disappeared after I removed all yalc installations (
yalc remove --all
in every repo and then verified thatyalc installations show
was empty)For the umpteenth time, if you want it fixed somebody needs to put together a repository, or some other reproduction, where we can see the error.
https://www.snoyman.com/blog/2017/10/effective-ways-help-from-maintainers
Interesting stuff. Thanks for the reproduction @bingtimren, sorry I missed it when you posted it!
If I run the tests with
-i
(i.e. forcing not to use workers) we get the correct errorSo there’s something wrong with (de)serialization of the
Map
s between workers. Will dig some more into this, but for people encountering this - running with-i
(short for--run-in-band
) should help you debugCreate a library project along with normal angular application
ng new my-workspace --createApplication="false"
cd my-workspace
ng generate application my-app
ng generate library my-lib
Output path for library project will be
dist/my-lib
and for application it shoulddist/my-app
In main tsconfig.json
"paths": { "@custom/my-lib": [ "dist/my-lib" ], "@custom/my-lib/*": [ "dist/my-lib/*" ] }
In jest.config.js add configuration for path mapper as
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths || {}, { prefix: '<rootDir>/' })
And in one of the spec/test file use the library as
import { Something} from '@custom/my-lib'
This fails at the above import with the error as
dupMap.get is not a function
. PS: Jasmine framework works fine for same testError:
Fix:
i output a log in this file (‘node_modules/jest-haste-map/build/ModuleMap.js:209:14’)
found array
because it found 2 pacakges, The answer above give me clue https://github.com/facebook/jest/issues/9021#issuecomment-539369466 @cameracker
Fixed 🚀🚀🚀🚀
Facing the same issue, I have my own custom library as shared project on angular. I have all necessary things like
moduleNameMapper
but still the issue is there.@SimenB just ran into this same problem, and it appears that I needed to ignore my output folders as @CameronAckermanSEL mentioned.
modulePathIgnorePatterns: ["packages/*/dist"]
for me, as I have a mono-repo where all package sources are inpackages/**/src/*
andpackages/**/dist
is where they build to.Hopefully someone else will find this helpful 😃
Hi! I managed to figure it out by reading over your lovely example project 😃
I was missing these properties:
Thanks!!
Meet this problem on an Angular app with some Angular libs, problem solved after adding
moduleNameMapper
to rootjest.config.js
.Let’s says we have a Angular lib placed at
projects/my-lib
, your roottsconfig
paths may look like thisYour root
jest.config.js
will need to setroots
to['<rootDir>/src']
moduleNameMapper
to map@my-scope/my-lib
toprojects/my-lib/src/public-api
And for my-lib
jest.config.js
setroots
to['<rootDir>/projects/my-lib']
I just resolved same problem with angular project by this config:
More at Medium
@WilliamChelman I’m unable to reproduce. I get the haste errors you note, but
moduleDirectories: ['node_modules', 'dist']
makes no differencemodulePathIgnorePatterns: ['/projects']
makes it find no testsmodyfing paths in tsconfig
entails so I didn’t touch that part.I haven’t done any angular since v1, so there might be some detail I’m missing.
Could you add a commit to that repo so that I can run
npm cit
and get thedupMap.get is not a function
error?Facing same issue. Anyone solved it?
I have the same issue in my Angular project. For some reason, when I remove
package.json
in (projects/my-project
, not the one in my root), the error is gone.I got this error when I added a path mapping to my project from my
tsconfig.spec.json
:And, my
jest.config.js
:However, I need my
package.json
there because it is the one that gets packaged by Angular.My workaround was to rename the path mapping of
my-project
tomy-project-api
, which fixed the issue.I have encountered this too in a mixed TypeScript and JavaScript project that uses Vue. As with the other posters, this happens when importing a class from another custom library that is included as a git submodule, referenced from
package.json
usingfile:
syntax. The error occurs several layers deep in the import hierarchy, not from an import from the .spec file itself. So the import hierarchy is:thing.spec.ts
import { MyComponent } from 'MyComponent.vue'
import { SomeModel } from '@my-org/package-name'
import { AnotherModel } from './local_file'
import { Utility } from '@my-org/another-package'
The error is raised at the fourth level down, when importing
Utility
from@my-org/another-package
:@CameronAckermanSEL I get that error too but it happens when I import a module from a custom library
This is the .spec.ts file
@vladyn, this indeed solves it in a cleaner way.
However, in my case, I thought I got rid of the yalc imported dependencies and reverted to the main package as I was done working on it and was about to commit the package depending on it. It seems that I need to go back to yalc’s documentation and see how to properly clean up (ie.
yalc remove --all
) and probably see if a commit hook exists to prevent putting a mess in the repo too.I have the same issue when I import a module from a custom library, just like @franjpr. Any solution?
@CameronAckermanSEL i’m getting this at the moment. Might you know why the solution above worked? and what might have caused this, this solution doesn’t seem work for me. I’m on lerna v2