How to uninstall global package with npm? - node.js

I have installed webpack in this way:
npm install -g webpack
Now want to uninstall it:
npm uninstall -g webpack
Check it again, it didn't been uninstalled:
webpack -v
3.1.0
Why?
And, I use this way can't find webpack:
npm list -g | grep webpack
This also didn't work:
npm uninstall -g webpack --save
After run this under a directory which included package.json:
npm uninstall webpack
npm WARN babel-loader#6.4.1 requires a peer of webpack#1 || 2 || ^2.1.0-beta || ^2.2.0-rc but none was installed.
npm WARN uglifyjs-webpack-plugin#0.3.1 requires a peer of uglify-js#^2.8.0 but none was installed.
npm WARN uglifyjs-webpack-plugin#0.3.1 requires a peer of webpack#^1.9 || ^2 || ^2.1.0-beta || ^2.2.0-rc but none was installed.

Try running both of the below commands:
npm uninstall -g webpack
npm uninstall webpack
I think you might be checking/looking at the local version after deleting only the global one.

You have to remove the packages manually installed globally on your os with sudo:
On OsX navigate to this directory
cd /usr/local/lib/node_modules
and
sudo rm -rf <packageName> // sudo rm -rf webpack

npm uninstall -g webpack
Worked for me, try running the command prompt in administrator mode.

You're most likely running a file from another install of npm.
Run which webpack to see where your shell is finding webpack.
Run npm root -g to find the root of the tree it's supposed to be in, being sure you're running the correct npm with npm -v and which npm.
If your webpack bin isn't in the npm root, reset your path to the webpack binary e.g. hash -d webpack in bash, and then go remove the unwanted npm root from your PATH variable. You can now use npm install -g webpack and npm uninstall -g webpack and it should work.

I have tried uninstalling global packages in several ways.
npm uninstall -g <package_name> this didn't work.
I managed to remove the global packages in the following way:
Goto terminal
Run this command npm list -g
Goto the path (C:\Users\user\AppData\Roaming\npm)
Delete all the related files to your package
Goto node_modules find and delete the package
This should work.
YW!

If you are using Node Version Manager (nvm) and you want to remove a global system package you will need to switch to that version. For example:
nvm use system
npm uninstall -g webpack

Try
chown -R "$(whoami)": "$(npm root -g)"
(you may need sudo for it) and then npm uninstall -g again

on windows run as administrator and run the command
npm uninstall -g webpack
on Linux
sudo npm uninstall -g webpack

In Windows, open the cmd with Administrator rights (start -> type cmd -> right-click on icon -> open with adm. rights), then navigate (in cmd type "cd ../../users/your_user_name") to your user folder, then run
npm uninstall -g webpack
or (I don't remember which one worked for me)
npm uninstall webpack

Had the same issue an none of the answer above helped.
My project was in a sub-directory of a larger project, which also had a node_modules folder.
That's why it says, something like "found another version higher in the tree."
Delete that folder, go back to your sub-dir, remove node_modules and package-lock.json, and finally run npm install again.

In archlinux, after running
npm uninstall -g <package_name>
you might have to manually enter /usr/lib/node_modules/ to remove the package's directory. This will prevent conflicts if you try reinstalling that package with a different package manager like pacman.

Building on #karthik006 's answer of deleting directly from the global node_module folder, if you are using nvm, you first need to decide from which version of node you want to delete the global package.
After that, switch to that version of node using nvm use <version>
Then run nvm which current to get the path where the executable for this version of node is saved.
The path will be something like <path to nvm node dir>/<node version>/bin/node
Using this path, cd into <path to nvm node dir>/<node version>/lib/node_modules and then rm -rf the packages that you want to remove.

On ubuntu the package I was on the hunt for was buried in ~/.npm/_npx/<chars>/node_modules/ and in ~/.npm/_npx/<chars>/node_modules/.bin/. I removed the bin and the directory and got the reinstall prompt.

Try This:
npm uninstall -g <package_name>
E.g: npm uninstall -g webpack

Related

npm init automatically create etc directory and `--save-dev` doesn't work

When I use npm init in cmd, npm creates an etc directory and package.json.
Then when I use npm install stylus --save-dev,the module is downloaded in node_modules directory. But I can not find dependency in package.json
and I realize I can use command ls, mkdir in cmd, which is also confusing.
after npm init I cat package.json
This is my initial directory after I use npm init, I get etc\ directory, which should not be in this directory
This is the directory after I use npm install stylus --save-dev
After installing stylus, I cat package.json, but no dependency in this file
I cannot find out what is wrong.
I'm using Windows 10
node-version 8.9.1
npm version 5.5.1
npx installed
You could try:
npm install -D stylus
or
npm install stylus -D
For multiple packages, do this:
npm install pkg1 pkg2 pkg3 -S
or
npm install -S pkg1 pkg2 pkg3
The difference between -S and -D is -S adds the package(s) to dependencies while -D adds to dev-dependencies.
-S and -D are flags, regardless of where you put it, be it before the package names or after the package names, npm will recognise them and act accordingly.
Check out this command
npm install --save-dev stylus
When you write stylus then --save-dev it is identifying --save-dev as package not as command.
For multiple package to install we write
npm install package1 package2 package3
I was also having the same problem. I assume that you would have set "prefix" key for npm local configuration. Running:
npm config delete prefix
may help. Then start your project:
npm init or npm init -y

Npm Install Permission Error

So I'm attempting to run npm install into my WP theme folder so I can convert .scss to css.
When I try to install this is all I see:
Web-Stations-Mac-Pro:ideabased matmorse$ npm install
npm WARN matmorse#1.0.0 No description
npm WARN matmorse#1.0.0 No repository field.
removed 7 packages in 1.661s
I've tried uninstalling NPM and NODE and re installing it with Brew. I've also tried correcting my permissions. The node_modules folder never installs.
NPM -v : 5.3.0
No - v: 8.3.0
Nothing seems to work.
You don't have package.json in the folder so you can't use the npm install command, since npm install looks for the package.json (that's why you are getting no description found error) .
You can use npm install node-sass to install the node-sass module.
You can refer the documentation for further clarification on npm install.
Use the following commands:
npm config get prefix
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

Cannot install #angular/cli

I am trying to work on angular2 for which I have installed nodeJS. I have followed the steps given here https://github.com/angular/angular-cli#prerequisites but there seems to be an issue. Here's what I did in the Command Prompt(Admin):
C:\WINDOWS\system32>node -v
v6.10.1
C:\WINDOWS\system32>npm -v
3.10.10
C:\WINDOWS\system32>npm install -g #angular/cli
[ ..............] / loadRequestedDeps: sill install loadAllDepsIntoIdealTree
My command prompt is stuck at this command and shows no sign of response. I will be glad if there are any suggestions on solving this issue of mine. Is there anything I am missing here?
Make sure.,you already installed nodejs.
npm install -g angular-cli
ng help
ng new PROJECT_NAME
cd PROJECT_NAME
ng serve
ng serve --host 0.0.0.0 --port 4201 --live-reload-port 49153
This command solved this problem for me:
npm install -g rimraf
The TLS key was a real problem and also install windows-tools does not help. After rimraf and using the right proxy settings and node_modules destination I can install angular-cli.
Can you try from the users directory C:\Users\userName or PC name just as shown in the below figure, and make sure you're not limited to any network related issues !
https://s-media-cache-ak0.pinimg.com/originals/87/50/24/87502456dd8043729b794bf00ee2c7e7.jpg
Try this -
Global Package :
npm uninstall -g #angular/cli
npm cache clean
npm install -g #angular/cli#latest
Local Package :
rm -rf node_modules dist # use rmdir /S/Q node_modules dist in Windows Command Prompt; use rm -r -fo node_modules,dist in Windows PowerShell
npm install --save-dev #angular/cli#latest
npm install
I faced the similar problem. Press Ctrl + C in the command Prompt. It will continue and it will not exit.
Run "npm install" inside this project folder to install all
dependencies.
Make sure you use the latest version of the CLI (upgrade guide
below)
Run "ng serve" to see the app in action.
Then,
Run the below commands to upgrade the latest version of the CLI - only use "sudo" on Mac/ Linux.
sudo npm uninstall -g angular-cli #angular/cli
sudo npm install -g #angular/cli
uninstall node.js
delete all node_modules from your directory
delete npm from AppData>Roaming>
delete npm_cache and all newly generated node files from the c:\users[username} directory.
install node.js
add local path as:
new>PATH>c:\users[username}\AppData\Roaming\npm
keep this before Temp path
in cmd: npm -v node -v C:\Users\693272>npm install -g #angular/cli
ng -v
(here 'ng' error should not come)
and now you can go to some other directory also and create your new project as
everything installed is set globally
C:\Users\693272>cd /
C:>d:
D:>ng new app1 -d
HOPE THIS HELPS!
Open PowerShell as admin:
Set-ExecutionPolicy RemoteSigned
npm cache clean --force
npm install -g npm#latest
npm config set registry http://registry.npmjs.org/
npm install -g #angular/cli --verbose
Start > Run > AppWiz.cpl > Uninstall node.js
Delete the node install directory removing remaining folders and files
Delete npm folder from Start > Run > %AppData% (AppData\Roaming)
If it exists delete npm-cache from the c:\users[username} directory
Install node.js the Latest Version and please use the default C:\Program Files\nodejs install path.
Open Cmd:
C:\Users\Jeremy>node -v
v17.1.0
C:\Users\Jeremy>npm -v
8.1.2

Cannot uninstall angular-cli

I've tried several times to uninstall my angular-cli in order to update it but even if I follow the instructions provided on github:
npm uninstall -g #angular/cli
npm cache clean
npm install -g #angular/cli#latest
When I check using the command ng --version I still get the old version :
angular-cli: 1.0.0-beta.26
node: 7.7.1
os: darwin x64
How can i fix this issue? Thanks
I have also faced the same issue in recent past for me I have do the following commands one by one in terminal.
sudo npm uninstall -g angular-cli
sudo npm cache clean
After this run
ng -v
If still get angular-cli version 1.0.0-beta.2x.x then run the following command
which ng
It will show the ng path. Go to the path and if it is linked with any file remove the same the link and actual ng file. In my case the link is in /usr/bin/ng and actual path of ng file is /lib/node_modules/#angular/cli/bin/ng.
sudo rm -rf /lib/node_modules/#angular/cli/bin/ng
sudo rm -rf /usr/bin/ng
Next you need to install #angular/cli using
sudo npm install -g #angular/cli
Close all the terminal and run ng -v and you are on. May be it will help someone. Thanks :)
If you are facing issue with angular/cli then use the following commands:
npm uninstall -g angular-cli to uninstall the angular/cli.
npm cache clean to clean your npm cache from app data folder under your username.
use npm cache verify to verify your cache whether it is corrupted or not.
use npm cache verify --force to clean your entire cache from your system.
Note:
You can also delete by the following the paths
C:\Users\"Your_syste_User_name"\AppData\Roaming\npm and C:\Users\"Your_syste_User_name"\AppData\Roaming\npm-cache
Then use the following command to install latest angular/cli version globally in your system.
npm install -g #angular/cli#latest
To get more information visit github angular-cli update.
Updating Angular CLI
https://github.com/angular/angular-cli#updating-angular-cli
If you're using Angular CLI 1.0.0-beta.28 or less, you need to uninstall angular-cli package first.
npm uninstall -g angular-cli
npm uninstall -g #angular/cli
npm cache clean
npm install -g #angular/cli#latest
Then when it gets done successfully you may try:
ng --version
This sometime happens when you had actually installed #angular/cli using yarn and not npm.
You can verify this by looking in to yarn's global install folder.
You can remove it from yarn using
yarn global remove #angular/cli
You are using the beta version of angular CLI you can do this way.
npm uninstall -g #angular/cli
npm uninstall -g angular/cli
Then type,
npm cache clean
Then go to the AppData folder which is hidden in your users and go to roaming folder which is inside AppData then go to npm folder and delete angular files in there and also go to npm-cache folder and delete angular components in there.After that restart your PC and type
npm install -g #angular/cli#latest
This worked for me ✌️
I found a solution, first, delete the ng file with
sudo rm /usr/bin/ng
then install nvm (you need to restart your terminal to use nvm).
then install and use node 6 via nvm
nvm install 6
nvm use 6
finally install angular cli
npm install -g #angular/cli
this worked for me, I wanted to update to v1.0 stable from 1.0.28 beta, but couldn't uninstall the beta version (same situation that you desrcibed).
Hope this works
The following approach worked for me:
npm uninstall -g #angular/cli
and
npm cache verify
I had the same problem. This doesn't work:
npm uninstall -g angular/cli
npm cache clean
instead use:
npm uninstall -g # angular/cli
I could not get the angular-cli to go away. I FINALLY figured out a way to find it on my windows machine. If you have Cygwin installed or you are running linux or mac you can run which ng and it will give you the directory the command is running from. In my case it was running from /c/Users/myuser/AppData/Roaming/npm/ng
I had angular-cli version 1.0.0-beta.28.3, and the only thing that worked for me was deleting the angular-cli directly from the global node_modules folder:
cd /usr/local/bin/lib/node_modules
rm -rf angular-cli
After that ng version output was, as expected:
command not found: ng
And I could install the latest angular-cli version:
npm install -g #angular/cli#latest
Hope it helps...
Step 1:
npm uninstall -g angular-cli
Step 2:
npm cache clean
Step 3:
npm cache verify
Step 4:
npm cache verify --force
Note:
You can also delete by the following the paths
C:\Users"System_name"\AppData\Roaming\npm and
C:\Users"System_name"\AppData\Roaming\npm-cache
Then
Step 5:
npm install -g #angular/cli#latest
You have to use (without #)
npm uninstall -g angular/cli
because
If you're using Angular CLI beta.28 or less, you need to uninstall angular-cli package. It should be done due to changing of package's name and scope from angular-cli to #angular/cli https://github.com/angular/angular-cli
Try to update via these steps found in the npm repo for the angular cli.
npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli#latest
There is also an angular cli migration guide. One other option (more involved) is to start a new project and migrate over by copying and pasting certain files. This can be found here in the "moving into the cli" section of the angular-cli github
Check if you have the hidden folder ".npm" in your Home directory and delete the old angular-cli folder.
While uninstalling Angular CLI I got the same message (as it had some permission issues):
Unable to delete .Staging folder
I tried deleting the .staging folder manually, but still got the same error. I logged in from my administrator account and tried deleting the staging folder again manually, but to no avail.
I tried this (run as Administrator):
npm uninstall -g #angular/cli
npm cache verify
npm install -g #angular/cli.
Then I tried creating the project from my normal user account and it worked.
For those using Windows, I had this issue because :
after running npm uninstall -g # angular/cli, the folder AppData\Roaming\npm were still containing a ng file
this file prevented a complete uninstall of the CLI
I tried then to remove the ng file manually, but for some reasons it was not possible (I did not have the right), even as admin.
The only hack I found was using a 'linux based' command (I used Git bash) as admin and removing this file from command line:
cd AppData/Roaming/npm
rm ng.cmd
For information: this was with the version 6 of the CLI. There is not problem anymore to remove manually this specific file after the update.

npm install from package.json, the dependancy -v yields command not found

Reinstalled node/npm from scratch and after npm install I can see the node_modules folder with all of the content from package.json. Checking gulp -v gives command not found in the command line on a mac. If I install gulp globally, gulp -v yields the version.
Is there a way of not installing all dependancies globally to use?
Generally gulp is a package which is used to run some task. These task might need to have administrator privileges. So it is better to install it globally using "npm install -g gulp" command. Here -g means "install it globally".
npm install installs the package locally.

Resources