facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.78k stars 26.87k forks source link

`react-scripts build` failed with error code ELIFECYCLE, errno 1 while adding 'node-thermal-printer' in src/index.js #2640

Closed rambabusaravanan closed 7 years ago

rambabusaravanan commented 7 years ago

Is this a bug report?

Yes

Can you reproduce the problem with npm 4.x?

Yes

Have you read the Troubleshooting section and searched the User Guide?

ELIFECYCLE, react-scripts build

Environment

  1. node -v: v8.0.0
  2. npm -v: 5.0.0
  3. yarn --version (if you use Yarn): NA
  4. npm ls react-scripts (if you haven’t ejected): react-scripts@1.0.7

Then, specify:

  1. Operating system: Ubuntu 16, Zorin OS 12.1
  2. Browser and version (if relevant): NA

Steps to Reproduce

  1. create a fresh app using create-react-app and $ npm install --save node-thermal-printer
  2. add the line import 'node-thermal-printer' in src/index.js
  3. $ npm run build

Expected Behavior

Successful Build.

Actual Behavior

Failed to compile with error code ELIFECYCLE, errno 1

Terminal

$ npm run build

sample-printer@0.1.0 build /home/andro/smartd.workspace/pos-space/sample-printer react-scripts build

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

static/js/main.47fb6eaa.js from UglifyJs Unexpected token: name (i) [./~/node-thermal-printer/node-thermal-printer.js:403,0][static/js/main.47fb6eaa.js:20938,12]

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! sample-printer@0.1.0 build: react-scripts build npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the sample-printer@0.1.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /home/andro/.npm/_logs/2017-06-27T16_14_58_135Z-debug.log

Log File https://github.com/rambabusaravanan/error-create-react-app/blob/master/2017-06-27T16_14_58_135Z-debug.log

Reproducible Demo

https://github.com/rambabusaravanan/error-create-react-app checkout the latest commit and npm install and perform npm run build

I'm building a cross-platform desktop app using electron and react and I'm using npm package 'node-thermal-printer' for usb thermal printer. The printer code works fine in the places where react-scripts build doesn't involve like

But the build fails, when I add the same code in src/index.js where react-scripts build failed with error code ELIFECYCLE, errno 1

viankakrisna commented 7 years ago

have you tried with node 6 or 7?

gaearon commented 7 years ago

This is the relevant line:

Unexpected token: name (i) [./~/node-thermal-printer/node-thermal-printer.js:403,0][static/js/main.47fb6eaa.js:20938,12]

It says on line 403 there's syntax Uglify doesn't understand.

Indeed, it's ES6:

let i = "QRCODE_CELLSIZE_".concat(settings.cellSize.toString())

If you compile the package down to ES5 before publishing, the issue will be fixed. You can use Babel for this.

Hope it helps, and thanks for a great issue report!

rambabusaravanan commented 7 years ago

@viankakrisna I just installed and tried with the versions v6.11.0 and v7.10.0. Still facing the same error.

rambabusaravanan commented 7 years ago

@gaearon Thanks for your answer.

As of I understood, the npm package 'node-thermal-printer' needs to be compiled down to ES5 before publishing for the reason Uglify doesn't understand a snippet in it. Am I correct?

Will it make sense, if i raise this as issue in 'node-thermal-printer' repository?

gaearon commented 7 years ago

Yes, this is correct! For some reason I assumed at first that you published that package—sorry for misunderstanding.

johnreynolds commented 6 years ago

I've been encountering this issue frequently while developing on AWS... I am pretty sure that it is related to poor connectivity between my workstation, my VPC, and my RDS service. Do you have suggestions on how to make startup more robust - able to recover from what I assume to be connection errors. Thanks.