JSmooth
JSmooth

Reputation: 327

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?

Upvotes: 4

Views: 2389

Answers (2)

lawrence-witt
lawrence-witt

Reputation: 9354

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.

Upvotes: 5

TGrif
TGrif

Reputation: 5931

This is because when you use npm install web3, npm will install web3 as a package dependency of your application.
The 5 dependencies you see in your node_module folder are the dependencies web3.js needs to run.

Not sure there is a builtin option do to it with npm, but you can install developpement version of this package with:

$ npm install --save https://github.com/ethereum/web3.js.git \
  && cd node_modules/web3/ \
  && npm install --only=dev

Or with something more traditional:

$ git clone https://github.com/ethereum/web3.js.git \
  && cd web3.js \
  && npm install --only=dev

Upvotes: 0

Related Questions