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
jest-haste-map: TypeError: dupMap.get is not a function #9021
Comments
Hi! I managed to figure it out by reading over your lovely example project :) I was missing these properties:
Thanks!! |
@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 |
@CameronAckermanSEL I get that error too but it happens when I import a module from a custom library
This is the .spec.ts file
|
Facing the same issue, I have my own custom library as shared project on angular. I have all necessary things like |
think i might have found what caused this. If you make any updates to package-lock this happens 😕 , when i removed any changes on my parent package lock. This error got resolved |
We should never have |
This fails at the above import with the error as |
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
The error is raised at the fourth level down, when importing
|
@isumeetk thanks, but could you do those steps in a repo and publish that? I tried to follow your steps but step 3 is unclear ( I could probably figure out these things if I spent some time on it, but it's a higher barrier than need be here. Either a repo I can clone, or a repl.it/codesandbox would be ideal. Ideally I should be able to clone, install, and run to see the error
Not sure what this means - jasmine instead of jest, or using jest-jasmine (which is the default test runner within jest)? |
Well this is interesting, while creating a repo to reproduce something made it work, both in reproducing repo and the my main repo. Still for people who want to go through the working structure here is the repo https://github.com/isumeetk/jest-angular-sample |
I have the same issue when I import a module from a custom library, just like @franjpr. |
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 |
not sure if this will help, but i am seeing this issue on a lerna repo i'm setting up. it seems to be an issue with symlinks and copies (still figuring it out since i inherited the code). deleted some symlinks/copies before running tests made this issue go away. main issue is that the [
[
"g",
[
[
"packages/components/lib/utils/package.json",
1
],
[
"packages/utils/package.json",
1
]
]
]
] i'm guessing something isn't creating a |
Hi all, Here is a minimal repository where this bug is reproduced: https://github.com/WilliamChelman/angular-jest-bug-repro How-to:
Some of the leads that were explored to fix this, but to no avail and usually end up with the "dupMap.get is not a function" error:
Solution that did work but felt dirty: change projects/me/lib-a/ng-package.json to {
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../node_modules/@me/lib-a", // here
"lib": {
"entryFile": "src/public-api.ts"
}
} So that the build is put in the node_modules directly, so then it's considered as any other external lib when tests are launched. To whoever read this, have a great day 😄 EDIT: doesn't really reproduce the dupMap.get error unfortunately, but leaving this at least for the ng-package.json hack that might help someone. |
@WilliamChelman I'm unable to reproduce. I get the haste errors you note, but
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 |
For some reason I'm currently unable to reproduce the dupMap.get error, even if it was that same error that brought me here... But now that I think of it (after sleeping a bit), it seems like the issue I have might be more for ts-jest in fact, since it looks like it is the tsconfig file that doesn't bode well with module resolution in this context. I'll see to create an issue on their side instead, thank you for your time @SimenB . |
I still think this is a bug in Jest somehow, if nothing else we should provide a better error. So if you figure out why you get the error please report back so we can improve things 👍 |
@SimenB just ran into this same problem, and it appears that I needed to ignore my output folders as @CameronAckermanSEL mentioned. Hopefully someone else will find this helpful :) |
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'm working in an Angular CLI project with an application and a library.
|
I just resolved same problem with angular project by this config: // jest.config.js
module.exports = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/src/setupJest.ts'],
testRegex: ...,
roots: ['<rootDir>/src'],
modulePaths: ['<rootDir>/dist'],
}; More at Medium |
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 ( |
I have the same issue in my Angular project. For some reason, when I remove I got this error when I added a path mapping to my project from my {
"compilerOptions": {
"paths": {
"my-project": ["projects/my-project/src/public-api.ts"]
}
}
} And, my module.exports = {
moduleNameMapper: {
"my-project": "<rootDir>/projects/my-project/src/public-api.ts"
},
}; However, I need my My workaround was to rename the path mapping of |
Can you put together a reproduction? I'd like to fix this so people don't need any workarounds (or at least give a clearer/actionable error) |
I have found the issue. I will describe it here and post a reproducible demo in a bit. Here is what happens: /my-app -> Installs @myproject/my-library and mocks some of the functions of the library in tests Case 1: If I run Jest version: ^24.9.0 |
have the same issue |
I encountered this issue today and packed it as a reproduction. I'm building my own typescript project template. I uses ts-jest. What I'm doing is trying to test the packed package. So my run script uses 'npm pack' to pack the package, extract it in a directory, 'npm link' from there, then install it back locally. Then I run a test that import my package using an absolute path as if from 'npm install'. To reproduce the issue:
|
After running into this issue myself, I encountered this helpful PR from the "isomorphic git" repo where they fixed this problem. While the PR doesn't contain much of an explanation, looking at it's very simple change was enough for me to identify the fix in my own repo. In my case, I have a monorepo using yarn workspaces and lerna where The error only appears for The diff from the "isomorphic git" fix which helped me solve this issue looks like: module.exports = {
+ modulePathIgnorePatterns: ['<rootDir>/website'],
testRegex: '/__tests__/(server-only\\.)?test-[^\\/]+\\.js',
moduleNameMapper: {
'^isomorphic-git$': '<rootDir>/src' cc @SimenB |
Interesting stuff. Thanks for the reproduction @bingtimren, sorry I missed it when you posted it! If I run the tests with
So there's something wrong with (de)serialization of the |
Reverting the |
I currently have a lerna project, this issue went away for me after upgrading to jest version 27.4.5. |
Error:
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 #9021 (comment) @cameracker Fixed 🚀🚀🚀🚀
|
Meet this problem on an Angular app with some Angular libs, problem solved after adding
Let's says we have a Angular lib placed at {
...others
"compilerOptions": {
"paths": {
"@my-scope/my-lib": [
"dist/my-lib/my-scope-my-lib",
"dist/my-lib"
]
}
}
} Your root
module.exports = {
roots: ['<rootDir>/src'],
moduleNameMapper: {
'@my-scope/my-lib': '<rootDir>/projects/my-lib/src/public-api',
},
}; And for my-lib
module.exports = {
roots: ['<rootDir>/projects/my-lib'],
}; |
This comment was marked as spam.
This comment was marked as spam.
I met the same problem and the error disappeared after I changed the packageJson.name of the root directory. But I need to keep this root packageJson.name. Any update about this issue? I'm using jest@29.5.0, and here is my tsconfg and jest config: "compilerOptions": {
"baseUrl": ".",
"paths": {
"my-root-package": "."
}
} modules.exports = {
rootDir: __dirname,
roots: [__dirname],
moduleNameMapper: {
'^my-root-package$': '<rootDir>'
}
}; |
on a |
Hoiw about adding (for these who are using yalc): |
I was gonna look into fixing the error in this case now, but the reproduction from #9021 (comment) is unfortunately deleted. Does anybody else have a small reproduction I can test with? |
@vilvai, almost 4 years later this comment just saved my day! |
@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. |
🐛 Bug Report
Running a jest test results in a test build failure:
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
andmaterial-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
My jest config:
The text was updated successfully, but these errors were encountered: