简体   繁体   中英

Is it okay to include npm in devdependencies in package.json?

I came across a nodejs repo that included npm in devdependencies. What would be the case that requires such config? Because, installing devdependencies already requires npm.

This makes sense if a repository uses NPM CLI internally and relies on specific NPM version instead of globally installed NPM, because the behaviour may be changed between major releases:

devDependencies: {
  "npm": "^2"
}

While

devDependencies: {
  "npm": "*"
}

won't make much sense, except that it will likely use latest stable NPM version, despite which version was installed globally on local system.

This also makes sense if NPM is used programmatically because global packages cannot be normally require d.

Modules which is required for your local development and does not required for production environment can be listed under devDependencies. Its is good to have devDependencies.

  • npm install will install both "dependencies" and "devDependencies"
  • npm install --production will only install "dependencies"
  • npm install --dev will only install "devDependencies"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM