npm - Notes10 Jun 2019
dependencies vs. development dependencies
install package as dependency:
$ npm install --save <package>
install package as development dependency:
$ npm install --save-dev <package>
- added to
dependenciessection of package.json
- application cannot run without it
transitive dependencies are installed
dependencies of your dependencies are installed recursively when you run
- added to
devDependenciessection of package.json
- packages are used in development environment only (say, Babel or Flow)
transitive development dependencies are not installed
that is if you install some package
fooand it has its own development dependencies, they are not installed when you run
peer dependencies tell npm:
I need this package, but I need the version that is part of the project, not some version private to my module.
By adding a package in peerDependencies you are saying:
- My code is compatible with this version of the package.
- If this package already exists in node_modules, do nothing.
- If this package doesn’t already exist in the node_modules directory or it is the wrong version, don’t add it. But, show a warning to the user that it wasn’t found.
don’t use peer dependencies if you are not npm package author - they are not automatically installed by npm (since version 3):
peer dependencies are not automatically installed unless a dependent package explicitly depends on the peer package itself