-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Import Json is not exposing properties as exports #3171
Comments
Why you say "does not work", what sort of error message do you get? |
This is because our current json import is through a wrapper looking like export default { "your_json_field": 1 }; A problem that might arise if we somehow allow |
Agreed but rollup / webpack for example does not care of this for example. The output will crash and that's normal. But the output error might be odd. |
They also don't output ESM. They output a script bundle. ES modules don't have an "export assignment" operator. There is no clean way to write it so that the whole of the JSON structure is made available. It is unlikely that rollup or webpack would just throw, because they don't have the same challenge, because they write it out in a special bundle format that isn't ESM and then wrap that in some sort of loader mechanism. I don't think "just failing" would be a good idea. All the following are valid [ "foo", "bar" ] "foo" 1 true While the primitives are unlikely, I don't think it is safe to assume an array at the top level would be unlikely, and it would be bad to not support that. So while I hate default exports, they are actually the only safe way to expose JSON as an ES module. |
@kitsonk i get your point about those case you mention. So assuming that the loading method for Json files is using only default exports, this might need to be documented. Like i said, other projets don't have the same implementation, so it could be confusing for users. |
Importing Json files only works this way:
this works:
this does not
The text was updated successfully, but these errors were encountered: