question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UglifyJs Syntax Error fails `npm run build` but not `npm start`

See original GitHub issue

Can you reproduce the problem with latest npm?

Yes.

Description

One of my npm modules causes the production (npm run build) builds to fail with an UglifyJs syntax error. However, I am able to run the app with npm start without any errors or problems.

Expected behavior

Should be able to build production build if development build is working.

Actual behavior

When running npm run build:

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

static/js/main.455932b3.js from UglifyJs
SyntaxError: Unexpected token: operator (>) [./~/evolutionary/select1.js:5,0]

Environment

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

  1. npm ls react-scripts (if you haven’t ejected): react-scripts@0.7.0
  2. node -v: v6.9.0
  3. npm -v: v3.10.9

Then, specify:

  1. Operating system: Mac OS X Sierra
  2. Browser and version: N/A

Reproducible Demo

  1. Generate a new project with create-react-app
  2. Run npm install evolutionary
  3. Put import 'evolutionary' at the top of index.js
  4. Run npm start. Confirm that app loads in browser w/ no errors.
  5. Run npm run build. Error appears

I’ve never used webpack, but from my experience with browserify I would assume that ES6 syntax in dependencies would be handled just as fine as my app code.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
cory-bakercommented, Aug 9, 2018

is there no solution to this???

3reactions
grecommented, Feb 13, 2018

It would be neat if create-react-app would support ES6 deps. there are a lot of dependencies I’m relying on (especially around cryptocurrencies/ethereum libs, that are primarly written for Node, and Node does support ES6 now!) that currently publish ES6 code (basically just code with let and arrow functions, nothing fancy) and i’m stuck by not being able to build my project.

Only way I have right now is to eject 😭everything was working smoothly except this. context: I don’t really want to eject because I’m actually writting a starter kit for writing ethereum apps (create-dapp).

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm run build uglifyjs: SyntaxError: Unexpected token: operator
The reason this is happening is because the ES6 code in your node_modules folder is not handled by create-react-app - it assumes they...
Read more >
terser - npm
Start using terser in your project by running `npm i terser`. ... uglify-es is no longer maintained and uglify-js does not support ES6+....
Read more >
How to Bundle JavaScript With Rollup — Step-by-Step Tutorial
Step 1: Install Rollup and create a configuration file. To get started, install Rollup with the following command: npm install --save-dev rollup. Next ......
Read more >
Build failed SyntaxError: Unexpected token: name (length)
json below. I have no problem running npm run start but failed to compile npm run build with the following error: SyntaxError: Unexpected...
Read more >
The best webpack configurations for React applications
Create React App (CRA) ships with webpack already under the hood, ... Run: $ npm run dev. Our app breaks, but it's not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found