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.

npm run build: fails in node_module on "class" or prototype defination

See original GitHub issue

Is this a bug report?

Not sure

Can you also reproduce the problem with npm 4.x?

Yes

Which terms did you search for in User Guide?

deploy configure

Environment

  1. node -v: v8.2.1
  2. npm -v: 5.3.0
  3. yarn --version (if you use Yarn):
  4. npm ls react-scripts (if you haven’t ejected): react-scripts@1.0.12

Then, specify:

  1. Operating system: ubuntu 16.04
  2. Browser and version (if relevant):

Steps to Reproduce

(Write your steps here:)

  1. npm i eosjs-ecc
  2. require(‘eosjs-ecc’)
  3. npm run build

Expected Behavior

success

Actual Behavior

npm run build

> react-scripts build

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

Failed to minify the code from this file: 

 	../ecc/src/key_public.js:25 

Read more here: http://bit.ly/2tRViJ9

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! keygen@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the keygen@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/.npm/_logs/2017-09-01T17_29_14_675Z-debug.log

Line 25 is either “class” in or in my local testing the first nonoccurence of “PublicKey.prototype.xxx =”

Reproducible Demo

none yet


Prototype and classes are pretty standard I’m not sure why this would fail…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Timercommented, Sep 18, 2017

@jcalfee ah, that’s where our misunderstanding is!

We do not compile any code from node_modules, so it stays as-is. Even if we were to convert to Uglify v3, uses of class would leak into code targeting IE 9 since it could be parsed then, but then bomb out the browser.

We do not compile node_modules because it’s incredibly slow and tends to break packages.

0reactions
jcalfeecommented, Sep 18, 2017

Your concern is about the build output code version. But this issue is about the version of the dependent modules going into the build… These should be two different things.

How about run the babel es2015 conversion before Uglify v2? This is the code I used in my module to make it comparable with create-react-app. If create-react-app did this then many other modules would be spared from having to generate and deploy the generated copy to npm (which is a challenge to keep in sync).I think this is reasonable since old browsers do not run code directly from npm, they always go though a build process.

The trick is to create the more compatible generated code as late as possible.

node_modules/babel-cli/bin/babel.js src --out-dir lib

package.json

"babel": {
    "presets": [
      "es2015"
    ]
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors when running npm run build - node.js - Stack Overflow
If the build is defined in your package.json file, make sure that you are executing the 'npm run build' in the correct folder...
Read more >
ts-error - npm
TL/DR: An extendable error class that actually works with TypeScript and ES6 support compatible with all environments, even very old browsers. ...
Read more >
Best Practices for Node.js Error-handling - Toptal
In this article, Toptal Full-stack Developer Jay Huang will introduce you to error-handling in Node.js and demonstrate how you can build a robust ......
Read more >
Errors | Node.js v19.3.0 Documentation
All JavaScript and system errors raised by Node.js inherit from, or are instances of, the standard JavaScript <Error> class and are guaranteed to...
Read more >
Strict mode - JavaScript - MDN Web Docs
Browsers not supporting strict mode will run strict mode code with ... be in strict mode delete Object.prototype; // Will not throw error...
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 Reddit Thread

No results found

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