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.

Error [SyntaxError]: Unexpected token: punc (.), During Build, when using optional chaining in the code

See original GitHub issue

Describe 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 image

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:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
evanwcommented, Jul 20, 2020

There are other possible target values too. For example, chrome79 would transform optional chaining but not import.meta because Chrome has supported import.meta since Chrome 64 but only started supporting optional chaining since Chrome 80. Would something like that work for you?

0reactions
yi-tuancommented, Sep 22, 2020

Has this been solved? I also had problems when I was building.

Read more comments on GitHub >

github_iconTop 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 >

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