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

JSON loader outputs invalid ESM code when a JSON file contains top-level properties like "dashed-key": "" #1598

Closed
sodatea opened this issue Sep 13, 2021 · 1 comment

Comments

@sodatea
Copy link

sodatea commented Sep 13, 2021

Reproduction

https://replit.com/@sodatea/esbuild-json-esm

Suggested solution

Top-level JSON properties whose keys are illegal identifiers should not be exported as named exports.

@evanw
Copy link
Owner

evanw commented Sep 13, 2021

This isn't invalid ESM. It's valid JavaScript, but it uses the ESNext feature known as arbitrary module namespace identifier names which is supported in recent versions of Chrome, Firefox, Safari, and Node. If you need the output to run in old JavaScript VMs that don't support certain ESNext features, make sure to specify the target setting such as --target=node12.22.4 (the target defaults to --target=esnext if it's not explicitly specified).

@sodatea sodatea closed this as completed Sep 14, 2021
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

2 participants