I have installed nodejs and then tried running the following command to install truffle suit and ganache as follows:
npm install -g truffle
npm install -g ganache
It got installed as follows:
Installing truffle and ganache
I also checked whether its present in the directories or not by running the command:
npm list -g
Yet when I run the command:
truffle -v
ganache -v
I get the error:
Error after installation
The package although it was installed globally, I couldn't access the package. I do have VS CODE and python 3.11 installed. Any suggestions to how can I use it globally?
I did try the following:
running npm config edit
changing the prefix to 'C:\Users\username\AppData\Roaming\npm'
adding that path to the system path variable
reinstalling the package with -g.
explicitly set the path by
npm config set prefix c:/Users//AppData/Roaming/npm
Change the permission of node global package without tampering with default file permission by
rather changing the directory itself along creating a new profile.
mkdir ~/.npm-global
npm config set prefix ~/.npm-global
set PATH=~/.npm-global/bin:$PATH
source ~/.profile
npm install -g <npm_packages>
But none of them worked
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
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
For some reason my npm is configured to install packages globally. I may have selected that option when I initially installed npm. However, I'm trying to change that configuration so npm installs locally. I googled and found this option:
npm config set global false
However, npm is still installing globally instead of locally. Am I missing a step or doing something incorrectly? Would you expect the command above to do what I need it to do?
npm installs packages locally by default. If you want to install a package globally use flag -g.
e.g. npm install my-package -g
I am new to npm, using package.json to define the dependencies. I am just curious where is those dependencies installed from?
First, npm checks your local machine for packages installed globally, or using the -g flag.
ie: if you used npm install -g moduleName
You can run npm list -g to figure out where that is on your machine.
Otherwise, npm goes to where you set the npm registry. By default this is npmjs.
If you want to see the default settings, run npm config list