-
Notifications
You must be signed in to change notification settings - Fork 72
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
Add explicit exports for node #611
Conversation
|
packages/protobuf/package.json
Outdated
"import": "./dist/proxy/index.js", | ||
"require": "./dist/cjs/index.js", | ||
"import": "./dist/proxy/index.js" | ||
"module": "./dist/esm/index.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause webpack, rollup, wmr (ref), esbuild (ref) to choose "import" over "module".
I don't think we can do that, because dist/proxy/index.js is an ESM wrapper that re-exports CJS to avoid the dual package hazard. I'm pretty sure it will cause problems for tree shaking, and possibly other issues.
For reference, here is how the current exports were tested: connectrpc/examples-es#1002
I think some other solution is necessary to fix the issue, while maintaining behavior for other consumers. I'm not entirely sure which one yet 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure we can find some better solutions to support dual package hazard and replace proxy with an alternative, yet make a fully standard ESM package with a standard import
export condition that works natively. (if this is your main concern to resolve) -- Feel free to direct me in discord (pi0), i can share my 50 cents of experience with dealing with ESM/CJS dual exports.
node
export condition
Updated PR as per #610 (comment) suggestion to use
Note: I have not e2e tested it against nitro. In theory it should work as we apply |
@pi0 thanks for modifying the PR with a quick fix. I can confirm that when I patch the package in node_modules with changes from this PR, the problem disappears. 🎉🎉 |
Hi, @pi0 appreciate your patience on this. We've been testing this extensively in Connect-ES also because we've noticed some similar issues with exports there. After a lot of investigation, we landed on the format specifed in this PR: connectrpc/connect-es#921. Would you be able to modify this PR so that the exports are in the same order and configured the same way? |
node
export condition
Hi @pi0. I actually pushed up the changes to your branch, I hope you don't mind. We'd like to get this fixed in all our npm packages as soon as possible. If things seem OK to you, we can merge this branch in. cc @timostamm |
Hi @pi0 , can you sign the CLA? |
Thanks for following and considering the change ❤️ #645 looks good! |
Also, FYI, this was released in v1.5.1 today. |
Resolves #610
By usingUsingimport
export condition first, we ask bundlers such as rollup to prefer an export that is compatible with native ESM (ie: directly importing in Node.js when externalized in build).node
export condition to prefer conditions that Node.js also natively prefers in runtime.See #610 (comment) for more context.