Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install from github repository not installing devDependencies

I am trying to install the ethereum/web3.js repository directly from GitHub (https://github.com/ethereum/web3.js), but the devDependencies are not being installed (only the dependencies). I have tried the following:

npm install https://github.com/ethereum/web3.js.git
npm install git+https://github.com/ethereum/web3.js.git
npm install ethereum/web3.js
npm install https://github.com/ethereum/web3.js.git --only=dev
npm install git+https://github.com/ethereum/web3.js.git --only=dev
npm install ethereum/web3.js --only=dev

The first 3 commands above will only install the 5 dependencies in the dependencies section of web3.js's package.json file, and the 3 "--only=dev" commands won't install anything.

"dependencies": {
    "bignumber.js": "git+https://github.com/frozeman/bignumber.js-
nolookahead.git",
    "crypto-js": "^3.1.4",
    "utf8": "^2.1.1",
    "xhr2": "*",
    "xmlhttprequest": "*"
},

When I use the following command, 288 packages are installed:

npm install web3 

How do I perform the same installation using the GitHub repository link?

like image 461
JSmooth Avatar asked Oct 23 '25 14:10

JSmooth


1 Answers

Spent a good hour fighting with this until I finally stumbled over this sentence on the npm-install documentation, under the section npm install <git remote url>:

If the package being installed contains a prepare script, its dependencies and devDependencies will be installed, and the prepare script will be run, before the package is packaged and installed.

This was perfect for my use case because I wanted to install my own private repo, then build it so the dist folder was available. I could just add this script to that private repo's package.json:

"scripts": {
  "prepare": "npm run build"
}

Now all the dependencies are available for the build step which will be run automatically on npm install. The prepare script is also run alongside a few other events, like packing and publishing, so make sure the rest of your build steps for that package reflect that.

Many public packages have this script already in place, so npm install will work on their git repos straight of out the box, but if the package does not (as it appears web3.js still does not) you may have to fork it and insert your own script.

like image 184
lawrence-witt Avatar answered Oct 26 '25 05:10

lawrence-witt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!