0

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.

  • Dupe: https://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies – Max Baldwin May 17 '18 at 19:26
  • Not really. It doesn't explain anything about NPM as a dependency. – Estus Flask May 17 '18 at 19:27
  • Including npm on a version will gurantee that this version of npm is available when using your package. The same is possible for node as well. TL;DR: It's a way of making sure the right version is used – Dominik May 17 '18 at 19:28
  • 1
    https://twitter.com/maybekatz/status/958157474397171712 – Dominik May 17 '18 at 19:36
  • @Dominik +1 on Locking node version $ npm install node@7 And one-off run with a specific node version $ npx -p node@6 npm test – naveen chandru May 17 '18 at 19:55
  • Are you sure if version of npm mentioned in devdependencies will be used when we run "npm run test" ? – naveen chandru May 17 '18 at 20:00
  • @naveenchandru No. Only if you explicitly run `npm` it through script, e.g. `"scripts": { "test": "npm run test2", "test2": "..." }`. It first runs global NPM and then local NPM version. But this doesn't matter because `npm run` is not a thing where npm versions behave differently (at least now). – Estus Flask May 17 '18 at 20:27
  • @estus Yes. That clarifies about global npm picking the mentioned npm version. Also, it may not make sense to use a specific npm version as such. But, good to know about the possibilities and behavior. – naveen chandru May 17 '18 at 20:37

2 Answers2

3

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 required.

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
0

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"
Ashok JayaPrakash
  • 2,115
  • 1
  • 16
  • 22