-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
mangled exports breaks with destructuring assignment of JSON imports #18278
Comments
Thank you for the issue, do you want to send a pr? |
Unfortunately I have no experience working with webpack internals or the details of project goals, so while I might be curious and have a dig to see what's what I couldn't commit to trying to fix this. |
/cc @ahabhgk What do you think? I don't like named export with JSON at all, because it volates a spec - there is no named export with JSON files, only |
I think there is already have a warning for named export with JSON webpack/lib/json/JsonParser.js Lines 62 to 63 in 7090328
What about disable named export with JSON in next major and when I will take a look and try to fix this bug in the next few days |
@ikydd-bbc Just intresting, why you used named export for JSON? Legacy code? |
@alexander-akait
|
@alopix Oh, I see, my mistake, sometimes the eyes are wrong 😄 We will look at this soon |
Also stumbled into this issue whilst upgrading a project to Webpack 5. I've noticed it doesn't seem to mangle all of the properties in the imported JSON, just the ones referenced wherever it has been imported. For example... Source file: import graphqlSpec from './graphqlSpec.json'; // {"data":{"schema":{"types":[...
const { types: schemaTypes } = graphqlSpec.data.schema;
schemaTypes.reduce(... Production build output: const i = JSON.parse('{"p":{"w":{"gK":[...etc'); // Objects within gK are **not** mangled
const { types: w } = i.p.w;
// Reading w fails because types has been mangled to gK
w.reduce(... |
Bug report
What is the current behavior?
As of 5.90.2 (including 5.91.0), destructuring assignment on a JSON import does not work because the property names have been changed (using default settings). Setting
optimization.mangleExports
tofalse
fixes this, but it worked fine in 5.90.1 and it works fine accessing properties with dot notation in 5.90.2+.Essentially the following:
If the current behavior is a bug, please provide the steps to reproduce.
https://github.com/ikydd-bbc/spike-webpack-minify-bug
What is the expected behavior?
Destructuring of JSON imports should work as they did previously in 5.90.1. We should be able to import a JSON file using the default export and then use destructuring assignment to pick out whatever properties we choose.
Other relevant information:
webpack version: 5.90.2 +
Node.js version: 18.19.0
Operating System: OSX
Additional tools:
The text was updated successfully, but these errors were encountered: