Minifying the code in 3 passes leads to a syntax error
See original GitHub issueDescribe 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
- Clone reproduction repo:
git clone git@github.com:cawa-93/vite-terser-issue.git
cd ./vite-terser-issue
- Install deps:
npm ci
- Build and serve
npm run build && npm run sevce
- 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:
- Created 2 years ago
- Comments:9 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s because terser moves the
preloadMarker
around in the 3rd pass. The marker need to be processed by thebuildImportAnalysisPlugin
later. Change of its position thus results in corrupted code.thx, I will do it right now.