[SOLVED] packages/minifyStdJS/plugin/minify-js.js:49:25: 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 trace when running the bundle-visualizer:

$ meteor run --extra-packages bundle-visualizer --production
...
=> Errors prevented startup:

   While minifying app code:
   packages/minifyStdJS/plugin/minify-js.js:49:25: terser minification error (SyntaxError:Unexpected token: punc (.))
   Source file: node_modules/pdfjs-dist/build/pdf.js  (2165:21)
   Line content:     if (arguments[0]?.annotationStorage !== undefined) {

   at maybeThrowMinifyErrorBySourceFile (packages/minifyStdJS/plugin/minify-js.js:49:25)
   at packages/minifyStdJS/plugin/minify-js.js:77:11
   at Array.forEach (<anonymous>)
   at MeteorMinifier.processFilesForBundle (packages/minifyStdJS/plugin/minify-js.js:66:11)

   While minifying app code:
   packages/minifyStdJS/plugin/minify-js.js:49:25: terser minification error (SyntaxError:Unexpected token: punc (.))
   Source file: node_modules/pdfjs-dist/build/pdf.js  (2165:21)
   Line content:     if (arguments[0]?.annotationStorage !== undefined) {

   at maybeThrowMinifyErrorBySourceFile (packages/minifyStdJS/plugin/minify-js.js:49:25)
   at packages/minifyStdJS/plugin/minify-js.js:77:11
   at Array.forEach (<anonymous>)
   at MeteorMinifier.processFilesForBundle (packages/minifyStdJS/plugin/minify-js.js:66:11)

=> Your application has errors. Waiting for file change.
...

My best guess is that this is a much more helpful error message than the one I am getting when trying to upgrade to meteor@2.3.5. Looks like optional chaining syntax (?.) is not supported.

How can I work around this?

Hi @aureooms ,

That is definitely strange since optional chaining is supported. Could you maybe try recompiling the package to see if that helps (not a solution, but looking for simple workarounds first).

Hi @storyteller,

I just tried that here Upgrade Meteor to 2.4 by make-github-pseudonymous-again · Pull Request #329 · infoderm/patients · GitHub, but to no avail.

I suspect this looks like an issue with whatever parser terser is using. Same flavor as [Resolved] Upgrading to 2.2.1 breaks module compilation.

I am trying to see if I can reproduce the error with https://try.terser.org and https://raw.githubusercontent.com/mozilla/pdfjs-dist/f06d82e191501230b4c75102a7f67bb53e50892c/build/pdf.js. What compiler options should I input? Default ones do not seem to yield an error.

Upgrading pdfjs-dist to the latest release does not fix it. The original offending line is gone but another one makes the parser choke:

...
   While minifying app code:
   packages/minifyStdJS/plugin/minify-js.js:49:25: terser minification error (SyntaxError:Unexpected token: punc (.))
   Source file: node_modules/pdfjs-dist/build/pdf.js  (2268:39)
   Line content:     return this._transport._htmlForXfa?.children[this._pageIndex] || null;

   at maybeThrowMinifyErrorBySourceFile (packages/minifyStdJS/plugin/minify-js.js:49:25)
   at packages/minifyStdJS/plugin/minify-js.js:77:11
   at Array.forEach (<anonymous>)
   at MeteorMinifier.processFilesForBundle (packages/minifyStdJS/plugin/minify-js.js:66:11)

   While minifying app code:
   packages/minifyStdJS/plugin/minify-js.js:49:25: terser minification error (SyntaxError:Unexpected token: punc (.))
   Source file: node_modules/pdfjs-dist/build/pdf.js  (2268:39)
   Line content:     return this._transport._htmlForXfa?.children[this._pageIndex] || null;

   at maybeThrowMinifyErrorBySourceFile (packages/minifyStdJS/plugin/minify-js.js:49:25)
   at packages/minifyStdJS/plugin/minify-js.js:77:11
   at Array.forEach (<anonymous>)
   at MeteorMinifier.processFilesForBundle (packages/minifyStdJS/plugin/minify-js.js:66:11)

I will be looking into this today. Don’t worry, we’ll fix things before the final release, that is why we have Release Candidates.

Also trying on the terser page is not going to work as they are one major version ahead. But these are the options for terser.minify:

const options = {
    compress: {
      drop_debugger: false,  // remove debugger; statements
      unused: false,         // drop unreferenced functions and variables
      dead_code: true,       // remove unreachable code
      global_defs: {
        "process.env.NODE_ENV": NODE_ENV
      }
    },
    // Fix issue #9866, as explained in this comment:
    // https://github.com/mishoo/UglifyJS2/issues/1753#issuecomment-324814782
    // And fix terser issue #117: https://github.com/terser-js/terser/issues/117
    safari10: true,          // set this option to true to work around the Safari 10/11 await bug
  };

@aureooms Could you make a simple reproduction so that we have a common codebase to debug?
Also could you try to recompile pdfjs-dist. Terser supports optional chaining from 5.2 and we are on 4.8 so I’m wondering what is going on here as maybe the input is not in the correct format.

@storyteller Here you go:

meteor create --release 2.4-rc.3 meteor-2.4-rc.3
cd meteor-2.4-rc.3
meteor npm i
meteor --production # OK
meteor npm i --save pdfjs-dist
echo "import pdfjs from 'pdfjs-dist';" >> client/main.jsx
echo "console.debug(pdfjs);" >> client/main.jsx
meteor --production # NOT OK

I had similar issue:

Errors prevented bundling: 47:3: Please do not use display: contents; if you have grid setting enabled
While minifying app code:
packages/minifyStdJS/plugin/minify-js.js:49:25: terser minification error (SyntaxError:Unexpected token: name (package))
Source file: packages/iron_core/lib/iron_core.js (258:29)
Line content: Iron.utils.debug = function (package) {

It seems that the minifier expects strict mode JS, but that is not always true for old packages.

@vlada13 try updating to the latest minify-js package, it should fix the issue.

Hi, minifier-js@2.7.1 and standard-minifier-js@2.7.1 are published.

A new meteor update --release 2.4 should update these packages for you if you are already running Meteor 2.4.

That fixed the issue. Thanks.

I’m still seeing this issue on 2.4. Reported here:

@storyteller I did a last attempt with 2.4.1 today and got the same error. I did not try to change terser’s version by hand. I chose the easy route and went straight for Meteor 2.5.0 which works! I consider this a SOLVED problem.

1 Like