Package.json and Dependencies
dependencies
vs devDependencies
Dependencies
Dependencies
that your project needs to run, like a library that provides functions that you call from your code.
dependencies
are installed on both:
- a directory that contains
package.json
npm i $package
on any other directory
devDependencies
Dependencies you only need during development or releasing, like compilers that take your code and compile it into javascript, test frameworks or documentation generators.
devDependencies
are installed on:
- a directory that contains
package.json
(unless given--production
flag)- or if
NODE_ENV=production
environment variable is set
- or if
- NOT installed on
npm install $package
on any other directory - are not installed
transitively
From end user perspective, you normally don't want the development dependencies, so you just get what is needed to use the package (dependencies
, not devDependencies
).
If you want to develop, you would need additional packages needed for dependencies like tests.
What is transitive
dependencies
are installed transitively
- if
A
requiresB
, andB
requiresC
, thenC
gets installed, otherwiseB
could not work, and neither wouldA
.
devDependencies
are not installed transitively.
- we don't need to test
B
to testA
, soB
's testing dependencies can be left out.