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

Using Uglify 3.0 results in errors #636

Closed
JeroenVinke opened this issue Jun 1, 2017 · 6 comments · Fixed by #662
Closed

Using Uglify 3.0 results in errors #636

JeroenVinke opened this issue Jun 1, 2017 · 6 comments · Fixed by #662

Comments

@JeroenVinke
Copy link
Collaborator

I'm submitting a bug report

  • Library Version:
    0.29.0

Please tell us about your environment:

  • Operating System:
    OSX 10.x|Linux (distro)|Windows [7|8|8.1|10]

  • Node Version:
    6.2.0

  • NPM Version:
    3.8.9
  • Browser:
    all | Chrome XX | Firefox XX | Edge XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView

  • Language:
    all | TypeScript X.X | ESNext

Current behavior:
When [email protected] is used, production builds fail:

image

Digging a bit further yields the follow error:

{ error: 
   { DefaultsError: `fromString` is not a supported option
       at DefaultsError.get (eval at <anonymous> (/Users/romainlanz/workspace/fivb/app.fivb.org/node_modules/uglify-js/tools/node.js:21:1), <anonymous>:86:23)
       at formatError (util.js:640:15)
       at formatValue (util.js:544:18)
       at formatProperty (util.js:798:15)
       at util.js:646:12
       at Array.map (native)
       at formatObject (util.js:645:15)
       at formatValue (util.js:585:16)
       at inspect (util.js:200:10)
       at exports.format (util.js:66:24)
     message: '`fromString` is not a supported option',
     defs: 
      { compress: {},
        ie8: false,
        keep_fnames: false,
        mangle: {},
        output: {},
        parse: {},
        sourceMap: false,
        timings: false,
        toplevel: false,
        warnings: false,
        wrap: false } } }

This is because Uglify-js@3 has a new API that is not backwards compatible with uglify-js@2:

image

Expected/desired behavior:

  • What is the expected behavior?
    aurelia-cli to work with uglify-js@3

  • What is the motivation / use case for changing the behavior?

@sam-piper
Copy link

We just tried upgrading to [email protected] - au build --env prod still fails, but there are no errors, instead the app-bundle.js / vendor-bundle.js files just contain the text "undefined".

Will wait for an update to aurelia-cli here.

@Aniel
Copy link

Aniel commented Jun 16, 2017

@sam-piper same here without --env The build works. If you specify an environment the bundle has the text undefined

@3cp
Copy link
Member

3cp commented Jun 21, 2017

There is another issue, besides unsupported "fromString".

line 242 in bundle.js

let minificationOptions = Object.assign({ fromString: true }, buildOptions.getValue('minify'));

When you assign an object {} with a string "lorem", you got {"0": "l", "1": "o", "2": "r", "3": "e", "4": "m"}, that's what happened here.

The "minify" value "stage & prod" was literally injected to minificationOptions like a char array.

I inspected minificationResult in few lines below. See error

'`0` is not a supported option'.

Didn't see "fromString" error here, probably on my computer, uglify reads minificationOptions property "0" before property "fromString".

@JeroenVinke , the question is why we need Object.assign({ fromString: true }, buildOptions.getValue('minify')) in the first place?

Also suggest to add checking on minificationResult (could return error) before using its code and map, to avoid unreadable error message from undefined sourcemap.

@JeroenVinke
Copy link
Collaborator Author

@huochunpeng we added that so that you can supply the minification options through aurelia.json. It looks like you have been looking into this. Would you like to create a PR to add support for uglifyjs@3?

@3cp
Copy link
Member

3cp commented Jun 21, 2017

I was trying to do a fix. So buildOptions.getValue('minify') was trying to get uglify options object from aurelia.json, but actually got the condition string "stage & prod", do you know what's the designed pattern to pass uglify options through aurelia.json?

@JeroenVinke
Copy link
Collaborator Author

@huochunpeng take a look at aurelia/framework#790

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

Successfully merging a pull request may close this issue.

4 participants