Parcel: Parcel 2: Unexpected token: punc (.)

Created on 10 Apr 2020  路  7Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

Build error when using targets in a monorepo, same config as https://github.com/parcel-bundler/parcel/issues/4392

馃毃 Build failed.
@parcel/optimizer-terser: Unexpected token: punc (.)
SyntaxError: Unexpected token: punc (.)
    at ee (/home/banou/dev/test/node_modules/terser/dist/bundle.min.js:1:19391)
    at c (/home/banou/dev/test/node_modules/terser/dist/bundle.min.js:1:27867)
    at l (/home/banou/dev/test/node_modules/terser/dist/bundle.min.js:1:27958)
    at f (/home/banou/dev/test/node_modules/terser/dist/bundle.min.js:1:28011)
    at G (/home/banou/dev/test/node_modules/terser/dist/bundle.min.js:1:41825)
    at De (/home/banou/dev/test/node_modules/terser/dist/bundle.min.js:1:48112)
    at /home/banou/dev/test/node_modules/terser/dist/bundle.min.js:1:48992
    at ye (/home/banou/dev/test/node_modules/terser/dist/bundle.min.js:1:49007)
    at ze (/home/banou/dev/test/node_modules/terser/dist/bundle.min.js:1:50261)
    at qe (/home/banou/dev/test/node_modules/terser/dist/bundle.min.js:1:50493)
error Command failed with exit code 1.

I managed to workaround the bug by removing the engines property in the target

  "targets": {
-    "appModern": {
-      "engines": {
-        "browsers": [
-          "last 1 chrome version"
-        ]
-      }
-    },
+    "appModern": {},
  },

Using ^2.0.0-nightly.180.

Bug 馃攲 Parcel 2 Plugins

Most helpful comment

I've just encountered this problem. I'm targeting newest Chrome browser which already has optional chaining. It's no longer proposal. Shouldn't this be just ignored?

All 7 comments

I guess this is because terser doesn't support optional chaining

echo " export function f(){return x?.y; }" | terser -mc --module
Parse error at 0:1,30
 export function f(){return x?.y; }
                              ^
ERROR: Unexpected token: punc (.)

We should definitely add a codeframe to that error.

For the cause itself:

  • would you understand that terser doesn't support that syntax and that you need to change your babelrc/browserslist?
  • or should we add a hint like "Terser might not support this syntax yes"

I mean, my .babelrc does contains @babel/plugin-proposal-optional-chaining, shouldn't it be okay ?

Yes, but if removing targets.appModern.engines changes the behaviour of babel, then your .babelrc isn't actually being used.

This is what the codeframe would look like without using source maps (this is potentially more correct since the unsupported syntax could have been inserted by a build step)

Bildschirmfoto 2020-04-10 um 12 05 09

On the other hand, it's a lot prettier displaying the source in this case:

Bildschirmfoto 2020-04-10 um 12 15 19

Why not both ? :)
Just kidding.

Maybe have the source display as normal log level, and the final result when using the verbose log level ?

Great idea.

Bildschirmfoto 2020-04-10 um 12 38 57
(I'm not entirely happy with the formatting of these diagnostics but we have bigger priorities right now.)

Will open a PR once https://github.com/parcel-bundler/source-map/issues/15 is resolved.

I've just encountered this problem. I'm targeting newest Chrome browser which already has optional chaining. It's no longer proposal. Shouldn't this be just ignored?

Was this page helpful?
0 / 5 - 0 ratings