Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected token: eof (undefined) during uglify'ing #684

Closed
devdemi opened this issue May 1, 2020 · 15 comments · Fixed by ciena-blueplanet/ember-bunsen-core#195
Closed

Comments

@devdemi
Copy link

devdemi commented May 1, 2020

Error during uglify'ing my project

 - broccoliBuilderErrorStack: SyntaxError: Unexpected token: eof (undefined)
    at ee (/usr/src/fe/node_modules/terser/dist/bundle.min.js:1:19541)
    at c (/usr/src/fe/node_modules/terser/dist/bundle.min.js:1:28031)
    at l (/usr/src/fe/node_modules/terser/dist/bundle.min.js:1:28122)
    at f (/usr/src/fe/node_modules/terser/dist/bundle.min.js:1:28175)
    at N (/usr/src/fe/node_modules/terser/dist/bundle.min.js:1:38279)
    at /usr/src/fe/node_modules/terser/dist/bundle.min.js:1:30375
    at /usr/src/fe/node_modules/terser/dist/bundle.min.js:1:28763
    at /usr/src/fe/node_modules/terser/dist/bundle.min.js:1:32107
    at /usr/src/fe/node_modules/terser/dist/bundle.min.js:1:32217
    at /usr/src/fe/node_modules/terser/dist/bundle.min.js:1:28763
  - code: [undefined]
  - codeFrame: Unexpected token: eof (undefined)
  - errorMessage: Unexpected token: eof (undefined)
        at UglifyWriter
-~- created here: -~-
    at UglifyWriter.Plugin (/usr/src/fe/node_modules/broccoli-plugin/index.js:7:31)
    at new UglifyWriter (/usr/src/fe/node_modules/broccoli-uglify-sourcemap/index.js:38:10)
    at UglifyWriter (/usr/src/fe/node_modules/broccoli-uglify-sourcemap/index.js:33:12)
    at Class.postprocessTree (/usr/src/fe/node_modules/ember-cli-uglify/index.js:54:50)
    at projectOrAddon.addons.reduce (/usr/src/fe/node_modules/ember-cli/lib/utilities/addon-process-tree.js:6:25)
    at Array.reduce (<anonymous>)
    at addonProcessTree (/usr/src/fe/node_modules/ember-cli/lib/utilities/addon-process-tree.js:4:32)
    at EmberApp.addonPostprocessTree (/usr/src/fe/node_modules/ember-cli/lib/broccoli/ember-app.js:866:12)
    at EmberApp.host.addonPostprocessTree (/usr/src/fe/node_modules/ember-auto-import/js/auto-import.js:108:20)
    at EmberApp.toTree (/usr/src/fe/node_modules/ember-cli/lib/broccoli/ember-app.js:1825:17)
@andygoalkeeper
Copy link

It may be related to release of moment.js 2.25.
Try to downgrade (add "moment": "2.24.0" in package.json).

moment/moment#5481

@fabiosantoscode
Copy link
Collaborator

Two things @devdemi:

  • Can you enable npmjs.com/source-map-support such that the stack traces are prettier?
  • Could you try updating moment to 2.25.1?

erikap added a commit to rollvolet/frontend-crm that referenced this issue May 2, 2020
@erikap
Copy link

erikap commented May 2, 2020

I still get the same error using moment 2.25.1. Rollback moment to v2.24.0, as suggested by @andygoalkeeper, seems to work 👍

@fabiosantoscode
Copy link
Collaborator

I believe this should be fixed at the moment level if reverting to 2.24.0 fixes it! I see a bunch of people pitching in on issues there, so I have hope that this problem is fixed eventually.

The error message is very interesting though. It's as if the file ends without closing a function or parens. Can anyone reproduce this same error message with another bundler such as webpack or rollup?

nvdk added a commit to lblod/frontend-gelinkt-notuleren that referenced this issue May 4, 2020
erikap added a commit to lblod/frontend-loket that referenced this issue May 5, 2020
@tdukai
Copy link

tdukai commented May 8, 2020

Rolling back moment package DOES NOT HELP!

@jrjohnson
Copy link

I'm not able to determine where in Moment this error is originating. Anyone have tips on enabling some debugging to get an idea about where to start looking?

@andygoalkeeper
Copy link

@jrjohnson

npm install -g ember-cli
ember new project
cd project
ember install ember-moment
ember build --environment=production

ember-cli/ember-cli#9206.
It's still actual for latest npm-package moment 2.25.3 (dependency for ember-moment).

@fabiosantoscode
Copy link
Collaborator

To ensure a revert:

If you're using yarn you can do as was mentioned here.

With npm, you can npm ls moment which shows every version of moment you might have deep in your dependency tree.

@fabiosantoscode
Copy link
Collaborator

fabiosantoscode commented May 9, 2020

@jrjohnson

What is the bundler?

I've been thinking of enabling some options to help debugging in the future, such as "snitching" what was the input code by placing it in some files, since 99% of terser users use it through a bundler, or making terser "pass-through", since it might be easier to change Terser options than to disable.

Something you can do for now, is to try and disable Terser entirely and look at the output. Is it valid javascript that you can run in your browser? If it is, that's a Terser bug. Except for ?. and ?? which aren't supported yet.

You can also enable source-map-support to make the stack trace make some more sense.

@jrjohnson
Copy link

Thanks @fabiosantoscode feels like I should have thought of that! The bundler is Broccoli and ember-cli, turning off minification there does produce invalid JS so this issue is not with terser. Now that I have some output to work with I'll start looking for the issue in there.

@fabiosantoscode
Copy link
Collaborator

Great, I'll be closing this then! Thanks!

@jrjohnson
Copy link

This should be fixed for ember apps with the release of ember-moment-shim v3.8.0 which no longer double minifies code from moment.

@fabiosantoscode
Copy link
Collaborator

What's going on? Double minifying is inefficient but it's certainly possible. It's not like Terser is unable to parse its own output.

@brianhjelle
Copy link

Bumbing ember-moment-shim to v3.8.0 fixed it for me. Thanks.

@jrjohnson
Copy link

@fabiosantoscode I don't think moment is minifying with terser internally, but I also don't think the issue is actually the minification itself as I can run terser min/moment.min.js -c sequences=30 -m safari10=true just fine against the minified moment source. I think the problem is in moment now including ES module imports. It's likely ember is going some transformation when it sees those, but it doesn't see them in minified code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants