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

Node EventEmitter polyfill includes ES6 code and breaks UglifyJS #1020

Closed
Grantlyk opened this issue Nov 8, 2016 · 17 comments
Closed

Node EventEmitter polyfill includes ES6 code and breaks UglifyJS #1020

Grantlyk opened this issue Nov 8, 2016 · 17 comments

Comments

@Grantlyk
Copy link

Grantlyk commented Nov 8, 2016

Description

When I run the npm run build command I expect a build folder to be created and populated with my expected transpiled results

Actual behavior

Instead I get the following error;

Creating an optimized production build...
Failed to compile.

static/js/main.f708940e.js from UglifyJs
SyntaxError: Unexpected token: operator (>) [/usr/lib/nodejs/util.js:30,0]

Environment

Run these commands in the project folder and fill in their results:

  1. npm ls react-scripts (if you haven’t ejected): [email protected]
  2. node -v: v6.9.1
  3. npm -v: v3.10.9

Then, specify:

  1. Operating system: Ubuntu 16.04.1

Additional

I've tried this on different node versions on Mac OS and everything runs fine there

@gaearon
Copy link
Contributor

gaearon commented Nov 8, 2016

Can you try downgrading Node to 6.7 or some earlier version?

It seems like at some point it started using ES6 syntax which means that syntax now becomes part of your modules if you use npm modules that import Node core modules. Which is confusing as hell. 😄

It would help if you included a project reproducing the problem.

@Grantlyk
Copy link
Author

Grantlyk commented Nov 9, 2016

Alright, is node version 6.7 before it started using ES6 syntax?

@thien-do
Copy link
Contributor

thien-do commented Nov 9, 2016

Yes it is. I think I can clarify @gaearon 's explanation for you 😄 :

  • At least one of your dependencies use Node core modules
  • These core modules are previously written in ES5, however, they are now using ES6 syntax in Node's LTS version (which is 6.9.1)
  • Create React App doesn't transpile dependencies' code, therefore, those ES6 syntax is included in your bundled code
  • When Uglify runs on your bundled code, it is failed because of those ES6 syntax

Solution:

  • Create React App will soon use Babili instead of Uglify, so you don't need to do anything.
  • In the meanwhile, I think down-grade NodeJS is a reasonable solution.

@gaearon should we write something about this in Readme?

@Grantlyk
Copy link
Author

Grantlyk commented Nov 9, 2016

@dvkndn

Thanks, your explanation was to the point, however I've downgraded to node version 6.7.0 and I'm still getting exactly the same error, I don't know loads about ubuntu but on ubuntu there is node and then a nodejs package that have to have some link between them. Could this at all be the issue?

@thien-do
Copy link
Contributor

thien-do commented Nov 9, 2016

Can you check the version of Node and NPM in the Mac (when everything is fine) then?

Also, it would be helpful if we can see the repo or a minimum version of it to reproduce the issue

@gaearon
Copy link
Contributor

gaearon commented Nov 9, 2016

I didn't mean to imply 6.7 is the specific version fixing the problem. It's just worth trying to see if any older versions work.

@Grantlyk
Copy link
Author

Regardless of the nodejs and npm version on the mac the scripts run absolutely fine, I've ejected to webpack for the time being and it's working like that -- I think it's something ubuntu related, I can't share the project it's currently in but I will try at some point to reproduce the issue and share that project

@lukejpreston
Copy link

I got the same error when running against 6.4 and 6.9 (in that order). Everything runs fine on the mac but not on ubunutu. Is there any way to resolve this issue?

@indrasantosa
Copy link

Happen to me as well, Im running 6.6.0, runs successfully on my mac, but not in ubuntu.

@baransu
Copy link

baransu commented Nov 16, 2016

Happens to me as well with Node 6.9.1 on Debian. Works perfect at my MacBook :/

@Grantlyk
Copy link
Author

Due to the feedback we've had here from people saying they have the same issue, i'm not going to bother creating a project for it, i'm sure this can be replicated by taking any project using create-react-app and running it in ubuntu with the versions mentioned here

@gaearon gaearon changed the title npm run build - Failed to compile. Node EventEmitter polyfill includes ES6 code and breaks UglifyJS Nov 20, 2016
@gaearon
Copy link
Contributor

gaearon commented Nov 20, 2016

Closing in favor of #1023 which was filed later but which has more details about the issue.
Please track (and help fix!) it there.

@gaearon gaearon closed this as completed Nov 20, 2016
@Pau1fitz
Copy link

Pau1fitz commented Apr 26, 2017

@Grantlyk hey, were you able to resolve this issue on ubuntu?

@gaearon
Copy link
Contributor

gaearon commented Apr 26, 2017

This was fixed in 0.8.2: #1023 (comment).
@Pau1fitz Which version of react-scripts are you using?

@Pau1fitz
Copy link

Pau1fitz commented Apr 26, 2017

@gaearon I have run npm run eject in the past so not sure I can see what version I am using. I have seen that it was fixed in issue #1023, but was unsure how I could fix the issue since I have ejected from the project.

@gaearon
Copy link
Contributor

gaearon commented Apr 26, 2017

The fix is here: https://github.com/facebookincubator/create-react-app/pull/1194/files.
You can apply it to config/paths.js in your ejected project.

@Pau1fitz
Copy link

thanks @gaearon

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants