Not able to uninstall outdated, probably unused NPM packages - node.js

I am trying to revive the React project of an ASP.net solution. I managed to clean up the package.json, but I am not able to remove two packages, which are neither used in the project nor defined in the package.json.
Two packages refuse deletion: The output of npm uninstall react-hammerjs still reads
npm WARN react-slick#0.14.11 requires a peer of react#^0.14.0 || ^15.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN react-slick#0.14.11 requires a peer of react-dom#^0.14.0 || ^15.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN react-hammerjs#0.5.0 requires a peer of react#^0.14.3 || ^15.0.0 but none is installed. You must install peer dependencies yourself.
Is this behavior expected?
The workaround to simply delete the corresponding subfolders within node_modules to remove react-slick#0.14.11 or react-hammerjs#0.5.0 is also not possible since no such directories exists. How do I proceed now?
PS: According to npm show react version I have version 16.9.0 of React if that matters.
Related questions:
NPM uninstall packages not working
Not able to uninstall NVM packages

In contrast to my previous assumption, the two packages are actually used by antd as a npm ls <package-name> revealed:
>npm ls react-hammerjs
ui#1.3.3.7 C:\myProjectUI
`-- antd#2.10.0
`-- rc-tabs#7.3.4
`-- react-hammerjs#0.5.0
>npm ls react-slick
ui#1.3.3.7 C:\myProjectUI
`-- antd#2.10.0
`-- react-slick#0.14.11
The issue was resolved with by updating the parent packages npm install --save antd#latest.

Related

React-native does not install with npm

When I run on my terminal the following command: npm install react-native I got this error.
npm WARN ajv-keywords#3.1.0 requires a peer of ajv#^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN react-native#0.55.4 requires a peer of react#16.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN abdu#1.0.0 No description
npm WARN abdu#1.0.0 No repository field.
+ react-native#0.55.4
updated 1 package in 22.645s
Can someone tell me please, how to fix this Issues? or what does mean?
Thanks a lot.
If you start a project from scratch I recommend you to use create-native-app from the official react-native doc : https://facebook.github.io/react-native/docs/getting-started.html
npm install -g create-react-native-app
Then run the following commands to create a new React Native project called "AwesomeProject":
create-react-native-app AwesomeProject
cd AwesomeProject
npm start
otherwise you should simply install missing peer dependancies
npm i -S install ajv react#16.3.1

upgrade a dependency of a global package in npm

npm version: 3.10.10
node version: 6.14.2
I need to upgrade some dependencies of npm to address some security warnings. An example: sshpk is a dependency of npm via http-signature and request:
bash-4.3# npm ls sshpk -g
/usr/local/lib
`-- npm#3.10.10
`-- request#2.75.0
`-- http-signature#1.1.1
`-- sshpk#1.10.1
I need sshpk to get upgraded to >=1.14.1, which is possible given the version lock in http-signature#1.1.1's package.json:
"dependencies": {
"assert-plus": "^0.2.0",
"jsprim": "^1.2.2",
"sshpk": "^1.7.0"
},
I've tried running npm upgrade -g npm#3 and npm --depth 9999 upgrade -g npm#3 without any success. It seems that npm doesn't continue in any update action since it notices we're already on the latest npm 3.x.x release of 3.10.10. I need to be able to keep npm's dependencies up-to-date as far as security patches go. Is this possible through npm update directly? I'm thinking of something similar to yarn upgrade <package>#<version> where it will traverse a package's sub-dependencies and upgrade those, even if the parent package isn't in need of a version change.
A reliable way to reinstall the package is to remove it or node_modules and install again.
Since NPM cannot be installed without NPM, this requires Node to be reinstalled.
An alternative is to install a spare NPM wrapper (e.g. npm3) and use it to reinstall main npm package
npm i -g npm3
rm -rf npm/
npm3 i -g npm#3
--force option can be used to reinstall the package, but it doesn't guarantee that package dependencies will be reinstalled.

eslint installation warnings. Need Clarification

In following a tutorial, I ran the following command to install eslint airbnb and a few dependencies
$ sudo npm install -g eslint-config-airbnb eslint-plugin-import eslint-plugin-react eslint-plugin-jsx-a11y
Upon completion I received a number of warnings
npm WARN eslint-plugin-react#7.6.0 requires a peer of eslint#^3.0.0 || ^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-import#2.8.0 requires a peer of eslint#2.x - 4.x but none is installed. You must install peer dependencies yourself.
npm WARN eslint-configeslint-config-airbnb-airbnb#16.1.0 requires a peer of eslint#^4.9.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-config-airbnb-base#12.1.0 requires a peer of eslint#^4.9.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-jsx-a11y#6.0.3 requires a peer of eslint#^3 || ^4 but none is installed. You must install peer dependencies yourself.
Ok, so.... I'm beginning to think the tutorial is outdated and something has changed. What (if anything) am I missing?
Please advise.
Each node package has dependencies it works perfectly or has been tested with hence the warning you get since they are the ones that are recommended or declared in the packages configs . Hence the warnings. It is recommended to follow the required packages to avoid errors, but most of the time unless you get an error then you should be good to go as the the alluded to package itself at whatever version exists.
In your case confirm you have eslint in you package.json, if not run:
npm install eslint --save-dev
All the warning are about peer dependencies. They are categorised as WARN instead of ERROR, because if your application code never touch such a dependency, you will be good. Fully tested code can ensure that these warnings can be safely ignored.
Excellent explanation to peer dependency

algular-cli installation issue with rxjs

I'm tryin' to install angular-cli into my linux Mint 32bit computer. But There's a failure to install it.
My command into terminal is:
npm install -g angular-cli
And the output:
npm WARN deprecated minimatch#2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
/home/shwokat/!/.npm-global-me/bin/ng -> /home/shwokat/!/.npm-global-me/lib/node_modules/angular-cli/bin/ng
/home/shwokat/!/.npm-global-me/lib
└─┬ angular-cli#1.0.0-beta.28.3
└── UNMET PEER DEPENDENCY rxjs#^5.0.1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#^1.0.0 (node_modules/angular-cli/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.0.17: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"ia32"})
npm WARN #angular/core#2.4.7 requires a peer of rxjs#^5.0.1 but none was installed.
Please write how to overcome this error & install angular-cli correctly ...
This is an issue with beta 30 of the CLI... the temporary fix is to install rxjs globally to resolve the dependency.
npm install rxjs -g
This has been addressed in the repo and will no longer be an issue with the next release.
UPDATE:
From #frankie4fingers in the comments, you may find success using the specific version:
npm install -g rxjs#5.0.1
I had the same issue, I was trying to install AngularJS 2 CLI using
npm install -g angular-cli
And I got the following warning and dependency error:
npm WARN deprecated angular-cli#1.0.0-beta.28.3: angular-cli has been renamed to #angular/cli. Please update your dependencies.
npm WARN deprecated minimatch#2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/angular-cli
/usr/local/lib
└─┬ angular-cli#1.0.0-beta.28.3
└── UNMET PEER DEPENDENCY rxjs#^5.0.1
So I tried to installing using #angular/cli instead of angular-cli and it worked.
npm install -g #angular/cli
I'm in exactly the same boat. I had a simple angular-cli repo from a couple of months ago, cloned it to a new machine running OSX Sierra, started getting these peer dependency errors when running npm install.
I've tried a fresh project and I can't even install angular-cli. Have tried installing rxjs globally, and by specific version.
While this posts adds little it is intended as corroborating evidence of the issue, and indication that the issue is likely non OS-specific.
[update] Frustratingly, running npm ls -g shows rxjs#5.0.1 is present.

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

Resources