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

React + create-react-app: Failed to minify error #299

Closed
sib-wolf opened this issue Oct 10, 2017 · 17 comments
Closed

React + create-react-app: Failed to minify error #299

sib-wolf opened this issue Oct 10, 2017 · 17 comments
Assignees

Comments

@sib-wolf
Copy link

I'm working on a React app. When running "npm run build" I receive the error below. Any help would be appreciated!

Failed to minify the code from this file:
 	./node_modules/ccxt/ccxt.js:51
Read more here: http://bit.ly/2tRViJ9
@kroitor
Copy link
Member

kroitor commented Oct 10, 2017

Hi, @sib-wolf! Thanks for reporting this! What's your version of Node?

@xpl
Copy link
Contributor

xpl commented Oct 10, 2017

What framework are you using? This is related to a minifier (probably, UglifyJS) that cannot understand ES6 code + your framework excludes node_modules from transpiling. You will need to edit your Webpack settings, adding CCXT to a babel-loader config. See also #225 (comment)

@sib-wolf
Copy link
Author

sib-wolf commented Oct 10, 2017

Hello! Thank you for the quick response.

I'm using create-react-app and am running node v8.6.0. Webpack and babel are already pre-packaged with create-react-app. In their documentation it says:

Converting to a Custom Setup

If you’re a power user and you aren’t happy with the default configuration, you can “eject” from the tool and use it as a boilerplate generator.

Running npm run eject copies all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. Commands like npm start and npm run build will still work, but they will point to the copied scripts so you can tweak them. At this point, you’re on your own.

I can try converting to a custom setup, but I don't think node_modules is being excluded. Have many other packages being pulled from that directory that are working.

@kroitor kroitor changed the title Failed to minify error React + create-react-app: Failed to minify error Oct 10, 2017
@xpl
Copy link
Contributor

xpl commented Oct 10, 2017

@sib-wolf Can you please upload somewhere a minimal project that demonstrates the error? A GitHub repo would be fine.

@sib-wolf
Copy link
Author

Created a fresh install of "create-react-app" and ran the command "npm install ccxt --save". Was able to reproduce the issue, same minify error occurs.

Repo with minimal project - https://github.com/sib-wolf/ccxt-test

@xpl
Copy link
Contributor

xpl commented Oct 10, 2017

@sib-wolf Seems that create-react-app doesn't provide any mechanism to override it's Webpack config except by running the npm run eject command (see the link provided).

Then you can edit the config/webpack.config.prod.js file, adding this code after the line 155:

{
   test: require.resolve('ccxt'),
   loader: require.resolve('babel-loader'),
   options: { compact: true },
},

I understand that it looks very hack-ish, and probably isn't the way the problem should be solved at all. We will consider to start distributing a pre-transpiled version of CCXT instead, but in the meantime, you can try this hack.

@kroitor
Copy link
Member

kroitor commented Oct 10, 2017

@sib-wolf does the above answer from @xpl solve this issue for you? I'd close this issue if it does, and if not, let us know. In the meantime we will restore the ES5-version of the library. We actually had it previously, but we thought it's not worth maintaining and removed it... Anyway, we'll do ccxt in ES5 again to avoid those problems in future, hope to upload soon.

@sib-wolf
Copy link
Author

Sorry, didn't have a chance to test it until now. Made a copy of the working directory, ran npm eject in it, and do not have that issue anymore.

Thank you both for your help! I'll be on the lookout for the version that comes out which doesn't require the "npm eject".

@kroitor
Copy link
Member

kroitor commented Oct 10, 2017

@sib-wolf do you mind if I close it for now? We will keep you updated on ES5 anyways. Feel free to reopen it or ask your questions, if any. Thx!

@kroitor kroitor closed this as completed Oct 10, 2017
@sib-wolf
Copy link
Author

nope, please do. thank you!

@trm313
Copy link

trm313 commented Oct 24, 2017

Hello - I wanted to add some additional information to this issue, since I'm experiencing it as well, but have a few extra observations.

Create-react-app build script fails with error:

Failed to compile.

static/js/main.495d93a9.js from UglifyJs
Unexpected token: name (BaseError) [../~/ccxt/ccxt.js:51,0][static/js/main.495d93a9.js:53892,6]

What's interesting, however, is that it didn't fail before. When I first installed the ccxt package ("ccxt": "^1.9.154") it was building fine, I even deployed it to heroku, and it's still live here: https://crypto-bot-trm313.herokuapp.com/ (git repo https://github.com/trm313/crypto-bot)

Yesterday, I tried to push some new changes which was when I experienced the build error for the first time. At this point, I had not modified the ccxt release I was using, although I did add some extra code with it in my app (specifically an API route that accessed the fetchTickers() function)

I tried updating to the latest release (1.9.250), but the error remains.

From the research I've done, I think you're correct that CRA can't handle any ES6 code, and as you pointed out, I'm sure ejecting the app would work as well, but obviously that's not ideal, so wanted to share the other info I had in case it points to an easier fix

@kroitor
Copy link
Member

kroitor commented Oct 24, 2017

@trm313 thx for reporting and for making the reason even more clear. We're still in doubt whether we should restore the ES5-version, or should we just wait for the migration to complete... 98% of browsers support ES6 by now, so we expect all those frameworks to obtain support for new syntax features as well. You see, the longer we support for outdated ES5-frameworks, the longer they remain outdated. We will reconsider this again in shortest time possible. Thx again!

@lpfeup
Copy link

lpfeup commented Dec 23, 2017

@kroitor any updates regarding the decision of distributing a pre-transpiled version? I am having the need to use babel just for transpiling the code both to node 6.x and to ES5 in different projects.

@kroitor
Copy link
Member

kroitor commented Dec 23, 2017

@lpfeup did you try this suggestion by @xpl: #299 (comment) ?

@lpfeup
Copy link

lpfeup commented Dec 23, 2017

@kroitor perhaps I should have asked this in another thread, since my issue is not directly related to this one. I need an ES5 version of this lib, which I am currently transpiling using babel. Just wanted to know if you were still considering distributing one.

Thanks

@kroitor
Copy link
Member

kroitor commented Dec 23, 2017

@lpfeup it isn't our topmost priority now, yet we still hope to do it asap. We are thankful for all contributions, your pull requests are welcome!

@pcriadoperez
Copy link
Contributor

hi,
I tried both @xpl hack and also following what they recommended with issue 225 but still running into the same issue. Any ideas?

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

No branches or pull requests

7 participants