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.

Minifying the code in 3 passes leads to a syntax error

See original GitHub issue

Describe the bug

If set up terser with passes >=3

terserOptions: {
  compress: {
    passes: 3
  }
}

The application does not load, you may see an error in the console:

Uncaught SyntaxError: identifier starts immediately after numeric literal

The cause of the problem is the minification of the code using a terser. It occurs if 3 or more passes are configured.

I thought this was a problem with the terser and tried for a long time to reproduce the error in REPL. But no matter what I do, everything works as expected and it happens only when the code is optimized through the Vite.

Reproduction

Reproduction repo: cawa-93/vite-terser-issue

  1. Clone reproduction repo: git clone git@github.com:cawa-93/vite-terser-issue.git
  2. cd ./vite-terser-issue
  3. Install deps: npm ci
  4. Build and serve npm run build && npm run sevce
  5. Open app http://localhost:5000

System Info

  System:
    OS: Windows 10 10.0.19042
    CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics
    Memory: 9.36 GB / 15.42 GB
  Binaries:
    Node: 14.16.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.9.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.423.0), Chromium (90.0.818.41)
    Internet Explorer: 11.0.19041.1
  npmPackages:
    @vitejs/plugin-vue: ^1.2.1 => 1.2.1
    vite: ^2.2.0 => 2.2.0

Used package manager: npm

Before submitting the issue, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the docs.
  • Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
  • Provide a description in this issue that describes the bug.
  • Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
sodateacommented, Jun 24, 2021

It’s because terser moves the preloadMarker around in the 3rd pass. The marker need to be processed by the buildImportAnalysisPlugin later. Change of its position thus results in corrupted code.

0reactions
ygj6commented, Jul 5, 2021

thx, I will do it right now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error when trying to minify objects - Stack Overflow
In non-supporting environments, these notations will lead to syntax errors. from MDN. In ES5 a JavaScript object will behave like JSON, ...
Read more >
Minifying - SurviveJS
Minification process analyzes your source code and turns it into a smaller form with the same meaning if you use safe transformations. ·...
Read more >
Terser vs. Uglify vs. babel-minify: Comparing JavaScript ...
Terser is one of the most popular and efficient libraries for minifying ES6 code. See how Terser compares to UglifyJS and babel-minify.
Read more >
SyntaxError: missing ; before statement - JavaScript | MDN
The JavaScript exception "missing ; before statement" occurs when there is a semicolon ( ; ) missing somewhere and can't be added by...
Read more >
3.13.3 - uglify-js - npm
UglifyJS is a JavaScript parser, minifier, compressor and beautifier ... In some cases more than one pass leads to further compressed code.
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