What is meant by UNMET OPTIONAL DEPENDENCY in npm list? - node.js

As I was checking my app's dependencies (and it's dependencies) I noticed some packages were marked as UNMET OPTIONAL DEPENDENCY like this image below, what do they mean?

Related

React with Webpacker is failing to load

Now that I have resolved my issue with Ruby, the React part with webpacker is failing to load probably as below.
yarn install v1.21.1
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#1.2.11: The platform "win32" is incompatible with this module.
info "fsevents#1.2.11" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > #babel/preset-react#7.8.3" has unmet peer dependency "#babel/core#^7.0.0-0".
warning "#babel/preset-react > #babel/plugin-transform-react-display-name#7.8.3" has unmet peer dependency "#babel/core#^7.0.0-0".
warning "#babel/preset-react > #babel/plugin-transform-react-jsx#7.8.3" has unmet peer dependency "#babel/core#^7.0.0-0".
warning "#babel/preset-react > #babel/plugin-transform-react-jsx-self#7.8.3" has unmet peer dependency "#babel/core#^7.0.0-0".
warning "#babel/preset-react > #babel/plugin-transform-react-jsx-source#7.8.3" has unmet peer dependency "#babel/core#^7.0.0-0".
warning "#babel/preset-react > #babel/plugin-transform-react-jsx > #babel/plugin-syntax-jsx#7.8.3" has unmet peer dependency "#babel/core#^7.0.0-0".
warning " > webpack-dev-server#3.10.1" has unmet peer dependency "webpack#^4.0.0 || ^5.0.0".
warning "webpack-dev-server > webpack-dev-middleware#3.7.2" has unmet peer dependency "webpack#^4.0.0".
[4/4] Building fresh packages...
Done in 71.58s.
Since I found this question while looking for the same problem, I will post my findings here as well.
Some background knowledge:
It are peer dependencies that are required here. Peer dependencies are dependencies that are not being installed when you run yarn or npm install. If you what to know more about peer dependencies and how the NPM package system work, read this article.
Node is using semantic versioning and this is explained here.
Now to this specific problem:
After reading the following issues on github:
Unmet babel core peer dependency
unmet peer dependency warnings using yarn
babel-core#^7.0.0-0 should be babel-core#^7.0.0-bridge.0
For me, I came to the conclusion I can ignore them since it seems to be a yarn bug not finding the correct package I have installed on my system. Never the less in case, I get problems at some point I need to do a closer deep dive into this. If this happens I will update the answer in the future.

Different versions of react and React native cause circular dependencies

I am having a question regarding version constraints.
First I was trying to install npm i react-native-message-bar --save
But then I got an Unmet Peer dependency: UNMET PEER DEPENDENCY react#16.1.0
So I did: npm install react#16.1.0
But then I got:
UNMET PEER DEPENDENCY react#16.1.0
npm WARN react-native#0.50.3 requires a peer of react#16.0.0 but none was installed.
So I have the feeling that I am running into circular dependencies.
Does this mean that I am not able to use the react-native-message-bar . with the current version of react?
I Would like to have some suggestions on how to resolve this.

npm unmet peer dependency on the package being installed

I'm a bit baffled as to why I get an unmet peer dependency on the exact package I'm trying to install.
I run:
npm install webpack#2.1.0-beta.27 --save-dev
Result:
angular2-webpack-starter#5.1.1 C:\src\angular2-webpack\angular2-webpack-starter
-- UNMET PEER DEPENDENCY webpack#2.1.0-beta.27
I'm running the latest version of node and npm.
Any help would be appreciated. Thanks.
Full output:
-- UNMET PEER DEPENDENCY webpack#2.1.0-beta.27
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.0.15: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN extract-text-webpack-plugin#1.0.1 requires a peer of webpack#^1.9.11 but none was installed.
npm ERR! code 1
The error isn't actually coming from Webpack, but instead (as we determined in the comments) it came from outdated versions of extract-text-webpack-plugin and bootstrap-loader. Since you're using Webpack 2, you'll need to use the v2 beta versions of your plugins.
To fix this, upgrade:
extract-text-webpack-plugin to v2.0.0-beta.4
bootstrap-loader to v2.0.0-beta.16.
It's a bit strange that npm highlighted Webpack as the missing peer dependency, but npm does tend to have quite unclear error messages that take a while to get used to.

How to install npm peer dependencies automatically?

For example, when I install Angular2:
npm install --save angular2
temp#1.0.0 /Users/doug/Projects/dougludlow/temp
├── angular2#2.0.0-beta.3
├── UNMET PEER DEPENDENCY es6-promise#^3.0.2
├── UNMET PEER DEPENDENCY es6-shim#^0.33.3
├── UNMET PEER DEPENDENCY reflect-metadata#0.1.2
├── UNMET PEER DEPENDENCY rxjs#5.0.0-beta.0
└── UNMET PEER DEPENDENCY zone.js#0.5.11
npm WARN angular2#2.0.0-beta.3 requires a peer of es6-promise#^3.0.2 but none was installed.
npm WARN angular2#2.0.0-beta.3 requires a peer of es6-shim#^0.33.3 but none was installed.
npm WARN angular2#2.0.0-beta.3 requires a peer of reflect-metadata#0.1.2 but none was installed.
npm WARN angular2#2.0.0-beta.3 requires a peer of rxjs#5.0.0-beta.0 but none was installed.
npm WARN angular2#2.0.0-beta.3 requires a peer of zone.js#0.5.11 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 angular2#2.0.0-beta.3 es6-promise#^3.0.2 es6-shim#^0.33.3 reflect-metadata#0.1.2 rxjs#5.0.0-beta.0 zone.js#0.5.11
What is the better way?
npm version 7 and newer
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.
Older Answer
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:
https://blog.npmjs.org/post/110924823920/npm-weekly-5
https://github.com/npm/npm/releases/tag/v3.0.0
So no, for the reasons given, you cannot install them automatically with npm 3 upwards.
I solved it by rewriting package.json with the exact values warnings were about.
Warnings when running npm:
npm WARN angular2#2.0.0-beta.3 requires a peer of es6-shim#^0.33.3 but none was installed.
npm WARN angular2#2.0.0-beta.3 requires a peer of reflect-metadata#0.1.2
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
Cheat code helpful in this scenario and some others...
├── UNMET PEER DEPENDENCY #angular/common#4.0.2
├── UNMET PEER DEPENDENCY #angular/compiler#4.0.2
├── UNMET PEER DEPENDENCY #angular/compiler-cli#4.0.2
├── UNMET PEER DEPENDENCY #angular/core#4.0.2
├── UNMET PEER DEPENDENCY #angular/forms#4.0.2
├── UNMET PEER DEPENDENCY #angular/http#4.0.2
├── UNMET PEER DEPENDENCY #angular/platform-browser#4.0.2
├── UNMET PEER DEPENDENCY #angular/platform-browser-dynamic#4.0.2 >
copy & paste your error into your code editor.
Highlight an unwanted part with your curser. In this case ├── UNMET PEER DEPENDENCY
Press command + d a bunch of times.
Press delete twice. (Press space if you accidentally highlighted ├── UNMET PEER DEPENDENCY )
Press up once. Add npm install
Press down once. Add --save
Copy your stuff back into the cli and run
npm install #angular/common#4.0.2 #angular/compiler#4.0.2 #angular/compiler-cli#4.0.2 #angular/core#4.0.2 #angular/forms#4.0.2 #angular/http#4.0.2 #angular/platform-browser#4.0.2 #angular/platform-browser-dynamic#4.0.2 --save
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.
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
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
Install yarn and then run:
yarn global add install-peerdeps

npm reports "requires (one version)' but will load (another version)"

Likely after cordove install with npm I got warning messages almost for every npm operations "requires colors#'>=0.6.0' but will load .. color"
D:\Workspaces\Enide-Studio-2014\OpenWith.js>npm i . -g
C:\Users\weibl\AppData\Roaming\npm\openwith -> C:\Users\weibl\AppData\Roaming\npm\node_modules\openwith\bin\openwith.js
npm WARN unmet dependency C:\Users\weibl\AppData\Roaming\npm\node_modules\phonegap\node_modules\cordova requires colors#'>=0.6.0' but will load
npm WARN unmet dependency C:\Users\weibl\AppData\Roaming\npm\node_modules\phonegap\node_modules\colors,
npm WARN unmet dependency which is version 0.6.0-1
npm WARN unmet dependency C:\Users\weibl\AppData\Roaming\npm\node_modules\phonegap\node_modules\node-static requires colors#'>=0.6.0' but will load
npm WARN unmet dependency C:\Users\weibl\AppData\Roaming\npm\node_modules\phonegap\node_modules\colors,
npm WARN unmet dependency which is version 0.6.0-1
openwith#0.11.0 C:\Users\weibl\AppData\Roaming\npm\node_modules\openwith
How to fix such npm errors?
As Andrew hinted, solution was to
npm -g update colors
Clean out the node-Modules folder and re-run:
npm install
At first, delete the phonegap\ folder in the location C:\Users\weibl\AppData\Roaming\npm\node_modules\. Of course, specific location will be different for others.
Then, proceed for any npm install/update command you want.

Resources