-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Support the "module" package.json field #2702
Comments
Are you interested in shipping a PR with this? :) |
Working on it right now :) |
Awesome 😎 |
@thymikee would you mind reviewing that PR? I asked a few others but they seem to be busy. |
Just wondering where we stand on this PR? Jest support for the "module" field would really help me out. |
I submitted a PR and it was ignored for a while, so I closed it. |
anyone can help unlock this freeze here? I am pretty much in the same situation than @probablyup and having this |
@canercandan Had same case as you. Got around the issue by configuring Jest with a custom Until the fields become configurable, this is the only (?) way to do what you need. You might need to write this resolver anyway, if you end up enabling watched-compilation for interdependent packages in your repo. |
@loklaan awesome thanks I will give it a try |
@probablyup looks like the maintainers are still interested in merging if you want to re-open the pull request: #2704 (comment) |
I’m currently away but might have some time to reboot the PR this weekend. If someone else wants to grab it that’s fine too. |
This is a touch of a blocker for me. I'm using lerna to manage my repository. At present I need to run babel to build my dependencies and then run jest. Otherwise jest won't be able to find my import since the path in the e.g. babel runs and generates files in in package.json: {
"main": "lib/index.js",
"jsnext:main": "src/index.js"
} I'm really excited about this PR as it will significantly speed up our test times. |
FYI @dmk255 and others who might have the same setup: moduleNameMapper: {
'^@myscope\\/([^/]+)': '<rootDir>/packages/$1/src',
}, |
@jeysal Thank you! That's a great idea. I actually use the projects feature in lerna so each project has its own Due to this I had to tweak your example slightly (I also needed to exclude one package): moduleNameMapper: {
'^@myscope\\/((?!config)[^\\/]+)': '<rootDir>/../$1/src',
}, |
So happy I found this thread. Ty @jeysal! This would be great to mentioned in the jest docs. The Babel site that has a section dedicated for monorepo concerns. If there was mention made some where close to the |
Thanks @jeysal for the excellent solution! In my case I also had imports to subdirectories of packages in the monorepo, so I had to do the following: moduleNameMapper: {
// Note that the order of these two is important!
'^@scope\\/([^/]+)\\/(.*)': '<rootDir>/../../packages/$1/src/$2', // import '@scope/package/sub/dir'
'^@scope\\/([^/]+)': '<rootDir>/../../packages/$1/src', }, // import '@scope/package'
} Even though I think jest now does support the |
Is this the code that needs to be changed to support this? https://github.com/facebook/jest/blob/master/packages/jest-resolve/src/defaultResolver.ts#L131 |
This feature is still definitely not supported. Are there any plans on finishing this after 3 years? See webpack which resolves it by default: https://webpack.js.org/configuration/resolve/#resolvemainfields |
Great idea, thanks @jeysal! Here's another possible mapping, for those who might have packages in nested directories.
moduleNameMapper: {
'^@scope\\/([^/]+)': '@scope/$1/src'
//Turns your @scope/package to @scope/package/src
} This might only work if you are already exposing the /src directory in the package.json alongside the /dist though... ie through |
Jest will never* support ESM through the When it comes to how you as users can use the (the same can (should) be done for the * of course things might change, but I highly doubt it |
Note that the official way of supporting this in node is through conditional exports: https://nodejs.org/api/esm.html#esm_conditional_exports When we support that (#9771) it might make sense to add an option to define "priorities" from that object so you could say you want |
Hi, Thanks! |
@makotoshimazu thank you so much for making that! Worked like a champ. FYI, I still had to add the es module in question to |
If I'm reading the code of Ideally the custom resolver could use In other words, I'd like to write a resolver like:
But I don't see how it can be done without changing https://github.com/facebook/jest/blob/master/packages/jest-resolve/src/defaultResolver.ts#L42 to pass down |
thanks @scinos! |
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. |
Similar to how there's an option to use "browser", it would be awesome to specify that Jest respect the "module" package.json field to resolve ES modules when using Babel with Jest.
The text was updated successfully, but these errors were encountered: