-
-
Notifications
You must be signed in to change notification settings - Fork 124
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 named imports for JSON #2
Support named imports for JSON #2
Comments
This problem is happening because Node.js is unable to detect whether a I worked on a fix in esbuild-kit/esm-loader#2, which detects the package type (by detecting nearest When the fix is merged, named imports on JSON will work for CommonJS contexts. However, it still won't work in Module contexts because native JSON modules don't support named imports by spec. We can technically override this behavior to support it but I'm not sure if we should because we don't back-port things like What do you think? |
I think using named import json is quite a common convention supported by most of the bundlers. Importing a single field of a json would also enable tree-shaking for a smaller footprint. I would expect this as I might run the .ts file with the runtime in development and use bundler for production. Without this, it would be quite a hassle to deal with. I am not sure if sacrificing this to match the spec is worth it here. |
Fair point. I actually encountered that exact problem when importing I'm OK with overriding JSON modules to add support in esm-loader as well. For reference on bundlers:
|
https://stackblitz.com/edit/node-ewwreq
The text was updated successfully, but these errors were encountered: