Giter Club home page Giter Club logo

Comments (7)

swateek avatar swateek commented on June 8, 2024 3

Facing this issue, exact error is

ERROR in my_backend.js from Terser
Invalid assignment

No solution yet.

from terser-webpack-plugin.

alexander-akait avatar alexander-akait commented on June 8, 2024 2

@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.

viddo avatar viddo commented on June 8, 2024 1

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.

alexander-akait avatar alexander-akait commented on June 8, 2024

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.

Alex-Willenbrink avatar Alex-Willenbrink commented on June 8, 2024

How do you disable the RemovePlugin?

from terser-webpack-plugin.

LitileXueZha avatar LitileXueZha commented on June 8, 2024

Here is a series of steps to locate the syntax error:

  1. disable terser plugin and enable source map
  2. run the output bundle main.js (without terser minified)
  3. 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.

rafael-ferreira-11 avatar rafael-ferreira-11 commented on June 8, 2024

Here is a series of steps to locate the syntax error:

  1. disable terser plugin and enable source map
  2. run the output bundle main.js (without terser optimized)
  3. 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

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.