question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Const reassignment in production build

See original GitHub issue

Bug report

What is the current behavior?

Webpack generates code using a const variable and then attempts to re-assign it. I suppose this could be due to the vue dependencies I’m using - but this code very much appears to be generated by webpack itself (or at least, half of it is, and then the libraryExport option attempts to overwrite it).

It seems like this shouldn’t be creating a block-scoped variable here at all, and assigning it to the global variable for the named library export.

If the current behavior is a bug, please provide the steps to reproduce.

Repo with minimal reproduction: https://github.com/richinfante/webpack-bug-repro

I’ve disabled the terser plugin in the test repo so output isn’t minified & optimized.

In short, running a production build generates the following code, which yields a syntax error in browsers:

/* harmony default export */ const empty_component = (component.exports);
empty_component = __webpack_exports__.default;

What is the expected behavior?

Webpack shouldn’t generate code that tries to re-assign a const variable.

Other relevant information: webpack version: 5.28.0 Node.js version: v14.16.0 Operating System: Arch Linux (5.11.8-arch1-1) Additional tools: Vue 2.6.12

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sokracommented, Mar 31, 2021

as workaround: rename your empty_component.vue file to something else.

1reaction
alexander-akaitcommented, Mar 31, 2021

Marked as critical-bug, we will try to fix it in near future

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why reassigning const producing error in console only if we ...
The Console now supports redeclaration of const statement, in addition to the existing let and class redeclarations. The inability to redeclare ...
Read more >
Reactjs Build Production: Optimize Performance - CopyCat Blog
In this article, we will be taking a deep dive into the Reactjs build production, deployment, and tips on optimising your app's performance....
Read more >
Use `const` and make your JavaScript code better - Medium
const prevents the variable to be assigned to another value. We could say it makes the pointer immutable, but it doesn't make the...
Read more >
11 Variables and assignment - Exploring JS
In JavaScript, const only means that the binding (the association between variable name and variable value) is immutable. The value itself may be...
Read more >
Optimizing Performance - React
Remember that you only need to do this for production builds. You shouldn't apply the terser plugin or the replace plugin with 'production'...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found