Skip to content
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

Unable to resolve size for dual published ESM and CJS #324

Closed
sinclairzx81 opened this issue Dec 20, 2023 · 1 comment
Closed

Unable to resolve size for dual published ESM and CJS #324

sinclairzx81 opened this issue Dec 20, 2023 · 1 comment

Comments

@sinclairzx81
Copy link

I currently have a package on npm which dual publishes for both ESM and CJS, however have noted that import-cost doesn't seem to be able to produce a size metric when importing the package. The specific package can be located at the following npm link.

https://www.npmjs.com/package/@sinclair/typebox/v/0.32.0-dev-28

and installed with

npm install @sinclair/typebox@0.32.0-dev-28

This package is configured somewhat differently in the respect it makes use of a technique referred to as package-json-redirect. This technique helps to ensure correct module resolution for node10 and pre and post node16 module resolution (with and without ESM), as well as helping TypeScript correctly resolve types for the configured moduleResolution target. Information on the technique can be found at the following URL.

https://github.com/andrewbranch/example-subpath-exports-ts-compat/tree/main/examples/node_modules/package-json-redirects

And do note that bundlephobia is able to make sense of these redirects.

https://bundlephobia.com/package/@sinclair/typebox@0.32.0-dev-28

It would be great if import-cost could produce a size metric for this library as quite a lot of work has been carried out recently to reduce ESM bundled output, this specifically to get utilization from the import-cost tool. If there's anything that can be done library side to provide configurations to import-cost to help it produce a metric, id be happy to explore that.

Thanks for this amazing tool.

@sinclairzx81
Copy link
Author

Going to close this one off as the issue appears to be TypeBox package.json configuration related, where WebPack silently fails when the default import target are not specified last.

Related Issue sinclairzx81/typebox#699

Webpack Assertion https://github.com/webpack/enhanced-resolve/blob/58464fc7cb56673c9aa849e68e6300239601e615/lib/util/entrypoints.js#L475

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant