adopted-ember-addons / ember-moment

MIT License
400 stars 122 forks source link

Using ember-moment in Ember 3.18 fails to produce production build #328

Closed deanmraz closed 4 years ago

deanmraz commented 4 years ago

Issue

Cannot create production builds. Fails during uglify.

Steps

  1. Create new ember app npm i -g ember-cli && ember new ember-moment-test
  2. Install ember moment cd ember-moment-test && ember install ember-moment
  3. Run production build ember build --environment=production

Error

Build Error (UglifyWriter)

Unexpected token: eof (undefined)

...

ERROR Summary:

  - broccoliBuilderErrorStack: SyntaxError: Unexpected token: eof (undefined)
    at ee (~/projects/ember-moment-test/node_modules/terser/dist/bundle.min.js:1:19541)
    at c (~/projects/ember-moment-test/node_modules/terser/dist/bundle.min.js:1:28031)
    at l (~/projects/ember-moment-test/node_modules/terser/dist/bundle.min.js:1:28122)
    at f (~/projects/ember-moment-test/node_modules/terser/dist/bundle.min.js:1:28175)
    at N (~/projects/ember-moment-test/node_modules/terser/dist/bundle.min.js:1:38279)
    at ~/projects/ember-moment-test/node_modules/terser/dist/bundle.min.js:1:30375
    at ~/projects/ember-moment-test/node_modules/terser/dist/bundle.min.js:1:28763
    at ~/projects/ember-moment-test/node_modules/terser/dist/bundle.min.js:1:32107
    at ~/projects/ember-moment-test/node_modules/terser/dist/bundle.min.js:1:32217
    at ~/projects/ember-moment-test/node_modules/terser/dist/bundle.min.js:1:28763
  - code: [undefined]
  - codeFrame: Unexpected token: eof (undefined)
  - errorMessage: Unexpected token: eof (undefined)
        at UglifyWriter

...
mschorsch commented 4 years ago

We have the same problem with ember@3.16 and sometimes get the following error (only in production build):

...
Merge error: conflicting capitalizations:
moment/locale/en-SG.js in /tmp/broccoli-14632r7VYmVxi9CXp/out-118-broccoli_persistent_filter_mapper
moment/locale/en-sg.js in /tmp/broccoli-14632r7VYmVxi9CXp/out-118-broccoli_persistent_filter_mapper
Remove one of the files and re-add it with matching capitalization.
...

The problem seems to be moment itself. Since moment@^2.25.0 the file en-SG.js was renamed to en-sg.js.

dmaok commented 4 years ago

@deanmraz I confirm the error with moment@^2.25.0. Just specify "moment": "2.24.0" for submodules. instruction for yarn, instruction for npm

deanmraz commented 4 years ago

@dmaok How would you implement that? It looks like npm pulled both versions of moment 2.24.0 & 2.25.0.

dmaok commented 4 years ago

@deanmraz, it is easier with yarn. In your package.json add block

  "resolutions": {
    "moment": "2.24.0"
  }

and then yarn install

deanmraz commented 4 years ago

@dmaok that worked, thank you!

This is a good short term fix, but what is the ideal solution? Does this need to be fixed in this repo or the actual moment repo?

jrjohnson commented 4 years ago

According to https://github.com/terser/terser/issues/684 this is a moment issue though there isn't a specific ticket there yet https://github.com/moment/moment/issues

jasonmit commented 4 years ago

Fixed in ember-cli-moment-shim@3.8.0 - thanks to @jrjohnson

deanmraz commented 4 years ago

@jasonmit confirmed! thanks everyone for the help