npm from v7 does auto-install, pnpm doesn't
npm starting from v7. Does install Peer Dependencies automatically https://github.com/npm/rfcs/blob/main/implemented/0025-install-peer-deps.md.
pnpm doesn't do it automatically. Even at this stage.
https://github.com/pnpm/pnpm/discussions/3995#discussioncomment-1893230
npm does the same way only with .npmrc
auto-install-peers = true
auto-install-peers=true now makes pnpm work the same way as npm v7. From pnpm v7.1.3 (ref)
And the with .npmrc
and not automatic
was a choice by the developers involved. There are those who were for and who weren't. (ref1, ref2)
.npmrc
To do it you have to create a .npmrc
file and add:
auto-install-peers = true
This is the best way. Because it creates consistency for all developers consuming the project and repo. Same config.
So in simplified terms, if you have some packages that require peers just add the config. You have a nice warning that reminds you in case there are packages with peer-dependencies
.
https://github.com/pnpm/pnpm/discussions/3995#discussioncomment-2797582
auto-install-peers=true now makes pnpm work the same way as npm v7. From pnpm v7.1.3
Does an --auto-install-peers
arg exists ? (No)
There is no --auto-install-peers
arg.
Can check here the feature ask here https://github.com/pnpm/pnpm/issues/5284
Denied.
And the why is understandable. .npmrc
is better for consistency. So that people pnpm install
and it always works the same. No forgetting anything.
Using install-peerdeps
I advise using .npmrc
. -> Native. straight forward.
Note: you may consider this tool. If you fall into some of pnpm bugs (ex: 1, ) and inconsistencies with peer-dependencies handling. Many issues are open. I would go with .pnpmrc first
. If any issues. I would use this tool.
https://www.npmjs.com/package/install-peerdeps
install-peerdeps
supports pnpm.
The tool is mentioned in eslint-config-airbnb
for example.
Example:
npx install-peerdeps --pnpm <your-package>
# or
npx install-peerdeps -P <your-package>
# as dev dep
npx install-peerdeps -P -D <your-package>
# Peers only
npx install-peerdeps -P -D --only-peers <your-package>
# or
npx install-peerdeps -P -D -o <your-package>
The package will automatically add the dependencies to package.json
in dependencies
or devDependencies
depending on the used flag.