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
Destructuring assignment of dynamically imported JSON files broken in 5.80.0 #17042
Comments
/cc @vankop Can you look at this? |
@jessevanassen |
For completeness, here's my reproduction. |
@jessevanassen as a work around can you get by this by dynamically importing an esm module which |
As a workaround, we rewrote it to the following which also works, but doesn't require a separate file: const json = (await import("./file.json")).default; It's purely the combination of dynamic imports and destructuring that triggers it, by taking out the destructuring the bug doesn't occur. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
@vankop friendly ping, do you need help with it? |
@alexander-akait hi, feel free to pick this up. dont have time for this now basically, you need to fix how used exports are detected in this case |
@vankop any hints where this is potentially being processed and needs to be fixed?) |
|
Destructuring dynamic JSON imports has been broken since webpack 5.80.0. See webpack/webpack#17042 . Work around the bug by avoiding the destructing pattern.
Another intresting bug: const { default: json, bar } = await import("./file.json");
console.log(json);
console.log(bar); json keep |
This issue had no activity for at least three months. It's subject to automatic issue closing if there is no activity in the next 15 days. |
Issue was closed because of inactivity. If you think this is still a valid issue, please file a new issue with additional information. |
Bug report
When destructuring the
default
out of a dynamically imported JSON file containing an object or array, the import will result in an empty container ({}
for a JSON file containing a filled object,[]
for a JSON file containing a filled array) instead of the actual import.What is the current behavior?
Only the empty container is returned, not the actual contents.
If the current behavior is a bug, please provide the steps to reproduce.
I've added the following test cases on this branch: https://github.com/jessevanassen/webpack/tree/dynamic-import-destructuring-assignment-json (comparison with main: main...jessevanassen:webpack:dynamic-import-destructuring-assignment-json)
Only the last test succeeds. The others fail like this:
The following constructs do work:
This leads me to believe that the recently merged #16995 might be the cause.
What is the expected behavior?
The parsed JSON should be imported.
Other relevant information:
webpack version: v5.80.0
Node.js version: v20.0.0
Operating System: Ubuntu 22.04.2 LTS
The text was updated successfully, but these errors were encountered: