-
Notifications
You must be signed in to change notification settings - Fork 525
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
export condition issues with packages using module
condition and commonJS modules
#1558
Comments
Thanks for reporting with reproduction! This issue seems happening with 2.5.x as well same as repro and also on latest edge. So probably not a regression of #1401 but something we might use to fix it for 2.6. Checking
It seems more likely that sanity is wrongly using export conditions. Sanity uses {
"node": {
"import": "./dist/index.cjs.js",
"module": "./dist/index.js"
}
} Oh yeah the other problem is with |
@sanity/client
@sanity/client
module
condition
This still seems reproducible on the edge: https://stackblitz.com/edit/github-81ghjr-ta9d1x?file=routes/index.ts,package.json,pnpm-lock.yaml. |
module
conditionmodule
condition and commonJS modules
Related issue: (Context: Discovered while testing nuxt ecosystem failed tests with https://github.com/harlan-zw/nuxt-og-image) Reproduction: https://stackblitz.com/edit/github-kkcfd3?file=package.json With #1401, we have added (ESM) export conditions to vercel/nft. When we try to trace files from a CommonJS package like |
Hello. What is the status of this issue? It is quite serious since it has caused me a bug due to which I am forced to pin an older version of the @bufbuild/protobuf package, as discussed here: bufbuild/protobuf-es#610. I provided a reproduction using nuxt which may be helpful to you: https://github.com/DavidDomkar/bufbuild-protobuf-error-reproduction. If you clone and do yarn install && yarn build && yarn preview, you can see the webpage with the error on localhost:3000. The problem is, despite the proxy folder being in node_modules of the @bufbuild/protobuf package, specified via "import" export, when running yarn build, the build process creates another node_modules directory in .output/server/node_modules and there the directory is missing, breaking the imports since nitro deletes all other exports except the "module" export. As pointed out by @timostamm in the linked issue. Can this somehow be resolved? |
Hi dear @daviddomkar thanks for making a reproduction and sharing reference. Checking protobuf-es package file it seems they also have the same export condition ordering issue. I'm afraid nothing much is that we can solve in nitro. If But the fix is pretty easy and straightforward for the package side i will try to follow up in the linked issue. 👍🏼 (bufbuild/protobuf-es#611) |
@pi0 Thank you so much for clarifying and giving a concrete solution. As I see here bufbuild/protobuf-es#611 it may not be as straightforward to fix because of other problems inside @bufbuild/protobuf. |
Hey @pi0 👋 We add the "module" export for bundlers, and use an ESM wrapper in "import" for Node.js to avoid the dual package hazard. I agree that using "module" might not be ideal, and I think we can change our exports as follows: "type": "module",
"exports": {
".": {
"node": {
"import": "./dist/proxy/index.js" // ESM wrapper specific to Node.js, re-exports CJS
},
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js" // pure ESM
} With Davids reproduction, That said, the fact that Nitro is using the "module" condition with the Looking at popular npm packages, 44 of them use "module" exports, and most of them prefer it over "import" or "default". Here is a gist analyzing them: https://gist.github.com/timostamm/8f4ba7b08a1cf429c80fac4fa44fa2cd ❤️ the universal features of Nitro, about time for such a project! |
Thanks for the through feedback @timostamm. Yes indeed it is a rollup behavior and as far as i could debug, even not directly in node-resolve plugin but more low-level places also use this condition. Really nothing easy to change on this side too. I think finally we have to hope more packages remove non-standard field. But in the meantime, i might make a auto patch behavior in Nitro to deoptmize tracer when the field is detected. Your idea also seems good for |
The issue with protobuf-es should be solved in the latest version (bufbuild/protobuf-es#645) I hope If more serious issues happening, we might opt for manual deoptimization ~> #1988 |
Possible regression from #1401. (Edge releases before then do not exhibit same behaviour.)
This reproduces for lots of Nuxt projects in https://github.com/nuxt/ecosystem-ci, particularly found this one from nuxt-modules/sanity.
Nitro-only reproduction: https://stackblitz.com/edit/github-81ghjr?file=routes/index.ts,package.json,nitro.config.ts
The text was updated successfully, but these errors were encountered: