Comments (7)
Facing this issue, exact error is
ERROR in my_backend.js from Terser
Invalid assignment
No solution yet.
from terser-webpack-plugin.
@swateek you have invalid a code Invalid assignment
, or something wrong on terser side, open a issue in the terser repo
from terser-webpack-plugin.
For anyone that also encounters this issue hoping for an answer (cc @rafael-ferreira-11), perhaps maybe this can help:
I ran into this same error today after updating npm dependencies. The concrete error I got:
ERROR in main.86104a64d160f4590554.js
main.86104a64d160f4590554.js from Terser plugin
Invalid assignment [main.86104a64d160f4590554.js:65189,36]
at js_error (/My/Project/Root/node_modules/terser/dist/bundle.min.js:554:11)
at croak (/My/Project/Root/node_modules/terser/dist/bundle.min.js:1278:9)
at maybe_assign (/My/Project/Root/node_modules/terser/dist/bundle.min.js:3488:13)
at expression (/My/Project/Root/node_modules/terser/dist/bundle.min.js:3497:24)
at simple_statement (/My/Project/Root/node_modules/terser/dist/bundle.min.js:1587:55)
at statement (/My/Project/Root/node_modules/terser/dist/bundle.min.js:1373:47)
at _embed_tokens_wrapper (/My/Project/Root/node_modules/terser/dist/bundle.min.js:1343:26)
at block_ (/My/Project/Root/node_modules/terser/dist/bundle.min.js:2178:20)
at _function_body (/My/Project/Root/node_modules/terser/dist/bundle.min.js:2090:21)
at arrow_function (/My/Project/Root/node_modules/terser/dist/bundle.min.js:1696:20)
Scrubbed real file paths obviously, doesn't matter.
Not very much to go on. and even harder since this err was effectively failing the webpack build so couldn't inspect the build output either referenced in the error (i.e. main.<hash>.js
)
I did know we had some process.env.<VAR>
assignments indeed, but despite removing all those the build failed, so could rule that out.
I opted to try to find the culprit by divide-and-conquer/binary search-ish approach instead, i.e. deleting or commenting out half the code in iterations, until I could identify where the issue was located. I started from the entry
points in my webpack config.
I didn't have to search for long, as the err turned out to be in a pretty shallow place. YMMV. Once I identified the file the error was pretty obvious indeed a invalid assignment, different but similar to process.env
substitution for the runtime why I didn't find it before. (custom code; not relevant here so omitting those details)
from terser-webpack-plugin.
We just wrapper around terser, please open issue in terser repo, we can't do something on our side, but this looks like parser error, maybe something create invalid es code, please try to disable RemovePlugin
or @babel/plugin-syntax-dynamic-import
and try to build again.
from terser-webpack-plugin.
How do you disable the RemovePlugin
?
from terser-webpack-plugin.
Here is a series of steps to locate the syntax error:
- disable terser plugin and enable source map
- run the output bundle
main.js
(without terser minified) - review the same syntax error and map to source files, now you can know how to fix it
In my case, when enabled 'production' mode, the webpack DefinePlugin
replace process.env.NODE_ENV
to "procution"
, so it throws a Invlid assignment error.
// source file
process.env.NODE_ENV = 'production';
// webpack output file
"production" = 'production';
^
Invalid assignment
from terser-webpack-plugin.
Here is a series of steps to locate the syntax error:
- disable terser plugin and enable source map
- run the output bundle
main.js
(without terser optimized)- review the same syntax error and map to source files, now you can know how to fix it
In my case, when enabled 'production' mode, the webpack
DefinePlugin
replaceprocess.env.NODE_ENV
to"procution"
, so it throws a Invlid assignment error.// source file process.env.NODE_ENV = 'production'; // webpack output file "production" = 'production'; ^ Invalid assignment
Would you mind explaining how you solved this issue @LitileXueZha ? I'm getting the same error on a quite big codebase
from terser-webpack-plugin.
Related Issues (20)
- ng build --dev heads to Error: Optimization error [main.fe9785e49a33b769.js]: SyntaxError: Unexpected token: punc ({) HOT 4
- ES2022 - terser can not handle syntax ( SyntaxError: Unexpected token: punc ({) ) HOT 3
- esbuild minify does not produce warnings HOT 3
- plugin running jest tests with maximum number of workers in Bitbucket Pipeline - causing exceeded memory limit errors HOT 4
- Format option "quote_keys" breaks private variable syntax HOT 1
- `nth_identifier` function that accesses global scope variable crashes HOT 8
- Worker is not a constructor HOT 2
- No documentation for MangleOptions HOT 1
- The type of Rules breaks HOT 3
- Bug: minified output causes a ReferenceError HOT 4
- When use esbuildMinify tree shaking is not effect HOT 3
- Allow terser-webpack-plugin to work with Node 18+ and webpack 4 default hashes without openssl-legacy-provider HOT 3
- Updater terser to 5.20.0 HOT 5
- Dont use workers for swc & esbuild minify HOT 1
- type error after upgrade from 5.2.0 to 5.3.9 HOT 1
- Source Map is inorrect when enable extractComments.banner of terser-webpack-plugin HOT 4
- Security issue with serialize-javascript dependency HOT 1
- Minifying moves await keyword inside inlined non-async function HOT 2
- Webpack config: After TypeScript type checking 6 errors appears. HOT 1
- Behavior of minified code is altered: when dependencies have imported JSON, JSON has names mangled, uncontrollable by terser mangle options HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terser-webpack-plugin.