Error [SyntaxError]: Unexpected token: punc (.), During Build, when using optional chaining in the code
See original GitHub issueDescribe the bug
When using terser
minification (Which is the default), and one has some optional chaining in the code. The build
fails with the error:
Error [SyntaxError]: Unexpected token: punc (.)
This is because, terser
does not support optional chaining
and a few other es2020
features.
Reproduction
This is because we chaged esbuildservice.ts
https://github.com/vitejs/vite/blob/master/src/node/esbuildService.ts#L72
to always target es2020
which is not always correct. We should either make it configurable, or read it from the tsconfig
file.
System Info
- required
vite
version: 1.0.0-beta.12 - required Operating System: OSX
- required Node version: 12.16.0
Logs (Optional if provided reproduction)
> 5985 | const hasChart = data?.getAnswer.answer.visualizations.some((viz) => viz.__typename === "ChartViz");
| ^ Unexpected token: punc (.)
5986 | const displayMode = data.getAnswer.answer.displayMode;
5987 | const suggestedDisplayMode = data?.getAnswer.answer.suggestedDisplayMode;
5988 | return {
[vite] Build errored out.
Error [SyntaxError]: Unexpected token: punc (.)
at ee (/Users/ashish.shubham/thoughtspot/node_modules/terser/dist/bundle.min.js:1:19541)
at c (/Users/ashish.shubham/thoughtspot/node_modules/terser/dist/bundle.min.js:1:28031)
at l (/Users/ashish.shubham/thoughtspot/node_modules/terser/dist/bundle.min.js:1:28122)
at f (/Users/ashish.shubham/thoughtspot/node_modules/terser/dist/bundle.min.js:1:28175)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:12 (8 by maintainers)
Top Results From Across the Web
terser minification error (SyntaxError:Unexpected token: punc ...
I am attempting to upgrade to meteor@2.4-rc.0 from meteor@2.2.3. Development with meteor run works fine. I am getting the following stack ...
Read more >UglifyJS: error when using optional chaining syntax
I can't find the operator listed in the parser's source code. Authors of the tool suggest to use transpilers like BabelJS before UglifyJS...
Read more >SyntaxError: Unexpected token - JavaScript - MDN Web Docs
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided.
Read more >ERR_UNHANDLED_REJECTION Unexpected token: punc ...
This error for me turned out to be unsupported handling of the new Optional Chaining operator ( foo?. ) — make sure if...
Read more >JavaScript : Uglify SyntaxError: Unexpected token: punc ()
JavaScript : Uglify SyntaxError : Unexpected token : punc ()) [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] JavaScript ...
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
There are other possible
target
values too. For example,chrome79
would transform optional chaining but notimport.meta
because Chrome has supportedimport.meta
since Chrome 64 but only started supporting optional chaining since Chrome 80. Would something like that work for you?Has this been solved? I also had problems when I was building.