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.
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:
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)

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

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.

(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?
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?