-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Bug?]: ERR_MODULE_NOT_FOUND with Yarn 4.6.0 #6646
Comments
@clemyan Could you let me know there is any progress? |
I have dug into this and determined this happens when all of the following is true
If all the the above is true, then the The PnP runtime injects itself into the Node process by monkey-patching the CJS module loader (e.g. The reason this issue does not happen for Yarn 4.5.3 is due to how Jest loads the transformer — it attempts Support for This can be fixed/worked around by:
As far as I can tell, the only way to fix this issue on our side is to revert our support for |
Thanks for the update. I was already wary of Yarn PnP needing to patch Node and TypeScript in order for it to function. I have a workaround to get my Jest example working, but this issue also causes my Storybook build to fail, and I haven't found a trivial workaround for that. It's probably time for me to move off of Yarn PnP, despite it's faster installation times. |
I feel difficult to understand about this decision. (I am using translator, I apologize if my tone as aggressive.) |
(This is a complicated topic and this is all based on my current understanding after doing some digging but I am open to being corrected and reconsider) First, let's talk about jest. When jest tries to load a transformer, it first attempts to
just to name a few. Now let's talk about Node. One of the things needed for Yarn PnP to work currently is the ability for userland code to inject itself into the resolution pipeline. When Node runs a
But there are many ways to load modules. For example, one may
This issue is a case of More generally, we are currently in a transitional period as the experimental loaders API gets iterated upon and a lot of churn is happening. Unfortunately, Node has not provided official alternatives to monkey-patching CJS until recently and there is little to no effort made to preserve the unofficial APIs (at no fault of anyone IMO) while fleshing out the loaders API. So where does that leave us? How can we address this issue, if at all?
All in all, it is impossible to fully support Again, I'm open to being corrected and reconsider if someone has more insight into this. |
(I am using an AI translator. I checked the translated text, but I ask for your understanding.) First of all, thank you for your detailed response. Here’s my understanding:
If my understanding is correct, it means that I am currently facing an actual problematic situation. To resolve this issue, I would like to know more about the As you mentioned, most of the problems are more pronounced when packages (or modules) being It seems that the only option I have is to resolve the issue with the problematic packages by patching them to include an exports field. I would be curious to hear your thoughts on this. Thank you, as always, for your dedication to Yarn. |
I mentioned Imagine I have a custom transformer: // jest.config.js
export default {
transform: {
'^.+\\.(js|jsx|ts|tsx)$': 'my-transformer',
},
}; {
"name": "my-transformer"
"exports": {
".": {
"require": "./some.cjs",
"import": "./other.mjs"
},
"./package.json": "./package.json"
}
} In this case, both As far actual workarounds, the ones I listed in my original response should work:
Patching a package's For your specific case, I would have to see a reproduction to help further. |
Thank your comment. Could I check a module in package that is I made reproduce of my case |
Self-service
Describe the bug
Module resolution fails for some combination of CJS and ESM as of Yarn 4.6.0. It works when using Yarn 4.5.3 or npm (with both Node 22.12.0 and Node 22.11.0).
To reproduce
yarn install
yarn test
Environment
Additional context
No response
The text was updated successfully, but these errors were encountered: