Reputation: 10940
For example, when I install Angular2:
npm install --save angular2
[email protected] /Users/doug/Projects/dougludlow/temp
├── [email protected]
├── UNMET PEER DEPENDENCY es6-promise@^3.0.2
├── UNMET PEER DEPENDENCY es6-shim@^0.33.3
├── UNMET PEER DEPENDENCY [email protected]
├── UNMET PEER DEPENDENCY [email protected]
└── UNMET PEER DEPENDENCY [email protected]
npm WARN [email protected] requires a peer of es6-promise@^3.0.2 but none was installed.
npm WARN [email protected] requires a peer of es6-shim@^0.33.3 but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.
Is there a magic flag that I can pass to npm that will install the peer dependencies as well? I haven't been able to find one... It's tedious to manually copy and paste the peer dependencies and make sure I have the correct versions.
In other words, I'd rather not have to do:
npm install --save [email protected] es6-promise@^3.0.2 es6-shim@^0.33.3 [email protected] [email protected] [email protected]
What is the better way?
Upvotes: 400
Views: 678380
Reputation: 387
I had the same issue with npm not installing peer dependencies of packages. I had tried so many solutions, this worked for me.
1. make sure you're using the correct versions of node, npm, ng:
node -v
npm -v
ng v
2. enter this command, to see where you have .npmrc files on your PC:
npm config ls -l
It will list your npm configuration, and you will see next to settings if it's overridden by some configuration.
In my case
;legacy-peer-deps = false; overridden by global config
, making it to true.
for ex.
at the end of generated settings, you will see a locations of .npmrc files that are overriding something.
Go to that config, and remove the legacy-peer-deps
setting. I had to remove this line in 2 different .npmrc files.
3. delete node_modules
of that project
I simply selected everything from node_modules, and hit delete. Previously closed visual studio for that project. And then removed empty node_modules folder.
4. clean cache with npm cache clean --force
5. if you made any changes to package-lock.json file, revert it.
6. Hit npm install
.
Peer dependencies should be installed correctly!
.angular
folder, and do ng build
, and ng serve
.
Upvotes: 0
Reputation: 1036
I solved it by rewriting package.json
with the exact values warnings were about.
Warnings when running npm
:
npm WARN [email protected] requires a peer of es6-shim@^0.33.3 but none was installed.
npm WARN [email protected] requires a peer of [email protected]
In package.json
, write
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
Then, delete node_modules
directory.
Finally, run the command below:
npm install
Upvotes: 45
Reputation: 3434
Here's a one liner for version 6.14.12 of npm:
npm install $(cut -d ' ' -f 6 <(npm ls 2>&1 | grep "npm ERR! peer dep missing:" | sed 's/\^.*|| //') | sed 's/,*$//' | sort | uniq | tr '\n' ' ')
It takes the error output from npm ls
and installs everything listed there.
Upvotes: 0
Reputation: 5901
npm v7 has reintroduced the automatic peerDependencies installation. Now in V7, as in versions before V3, you only need to do an npm i
and all peerDependences should be automatically installed.
They had made some changes to fix old problems as version compatibility across multiple dependants. You can see the discussion and the announcement.
The automatic install of peer dependencies was explicitly removed with npm 3, as it cause more problems than it tried to solve. You can read about it here for example:
So no, for the reasons given, you cannot install them automatically with npm 3 upwards.
Upvotes: 295
Reputation: 637
I was facing the same issue, lucky I found an alternative way to install peer dependencies along with the install command.
Step 1: $ npm i npm-install-peers -D
for more clarity about the plugin: https://www.npmjs.com/package/npm-install-peers
Step 2: Update package.json
for magical script
....
"scripts": {
...
"postinstall": "npm-install-peers"
},
....
Step 3: Just need to hit the install command to get installed all plugins
$ npm install
Upvotes: 7
Reputation: 411
Cheat code helpful in this scenario and some others...
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected] >
├── UNMET PEER DEPENDENCY
├── UNMET PEER DEPENDENCY
)npm install
--save
npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] --save
Upvotes: 24
Reputation: 5627
I experienced these errors when I was developing an npm package that had peerDependencies
. I had to ensure that any peerDependencies
were also listed as devDependencies
. The project would not automatically use the globally installed packages.
Upvotes: 13
Reputation: 2506
The project npm-install-peers
will detect peers and install them.
As of v1.0.1
it doesn't support writing back to the package.json
automatically, which would essentially solve our need here.
Please add your support to issue in flight: https://github.com/spatie/npm-install-peers/issues/4
Upvotes: 11