sh: 1: node: Permission denied - node.js

Tried to run this command on ubuntu 18.04
npm install -g pngquant-bin
but I got this error,
[..................] | fetchMetadata: sill resolveWithNewModule npm-conf#1.1.3 checking installable status
npm WARN deprecated gulp-util#3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
/root/.nvm/versions/node/v10.8.0/bin/pngquant -> /root/.nvm/versions/node/v10.8.0/lib/node_modules/pngquant-bin/cli.js
> pngquant-bin#5.0.0 postinstall /root/.nvm/versions/node/v10.8.0/lib/node_modules/pngquant-bin
> node lib/install.js
sh: 1: node: Permission denied
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! pngquant-bin#5.0.0 postinstall: `node lib/install.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the pngquant-bin#5.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-08-12T18_08_02_197Z-debug.log
Do you do you know how to deal with this?
I tried every solution found in this articles yet not succeeded.

Got the same error sh: 1: node: Permission denied
So this worked for me
npm config set user 0
npm config set unsafe-perm true

These issues happen because of broken packages. Go to the main folder. If using Linux use command
sudo rm -rf node_modules.
After that run this command if you are using yarn
yarn install
If you are using npm run this command
npm install

Delete the node_modules and install it again
sudo rm -rf node_modules
npm install

in fact, npm can't use root account to install anything. if you use root account, npm will create a non-permission account to install. in this case, if the package need to execute writeFile or other operation which need permission, the error node: Permission denied will be raised.
so, you can choose optional arbitrary under:
npm install xxx --unsafe-perm
npm config set unsafe-perm true
create high-permission account dedicate to execute npm install

In my case it was a silly typo, I was forgotten to add node into the front of the start command in package.json. So I've changed:
"scripts": {
"start": "app/server.js"
}
... to:
"scripts": {
"start": "node app/server.js"
}

The /root/.npm/... log path in your original message shows you're already running as root, and (despite what others advise) I'd say this is most likely causing your problem.
My (limited) experience running Node as root is that most npm install runs get quite a long way, but then fail with some variation on the error you showed. The only reliable solution I've found is to not run Node or npm as root at all on Ubuntu. Just use a normal user account to download and unpack the Node installation.
At least one problem with running as root for me turned out to be because some dependency-of-a-dependency npm install script was calling setuid to switch to a less-privileged user. For some reason, it chose UID 500—which doesn't exist on Ubuntu—and consequently lost all its privileges. The 'Permission denied' errors were therefore because I was running as root; setuid doesn't work for a normal user.
I believe this is related to Error: setuid user id does not exist npm ERR! when npm install forever -g.

Solved my problem chmod -R a+x node_modules
As far as my understanding goes the os is blocking your ability to execute commands described in node_modules so by my understanding what this command does is say everything in node_modules is okay to execute.
By the time I found the solution it was 4 AM, so I didn't really bother to figure out what I actually did. If someone knows what -R a+x node_modules does exactly feel free to drop it in the commands and I will make an edit.

I make the chown to project user owner (in USERID) dir and resolv the "permission denied" problem:
sudo chown -R USERID.USERID *

Additionally (and this might be useful for docker) you can override this configuration setting globally via the environment variable npm_config_user -- for example:
ENV npm_config_user=root

I ran into the same error an nothing really helped. I found a medium article explaining how to set up an angular build management. For some reason adding
- npm link #angular/cli#13.2.5
to my build script made it. I basically added all of the recommendations above. So my build script now looks like this
- ...
- npm config set user 0
- npm config set unsafe-perm true
- npm i --force
- npm link #angular/cli#13.2.5
- ...
I hope it helps! I would be happy if someone could explain why it actually worked.

This is an old question but maybe someone still need some help.
This errors often is displayed because you have defined in the package.json just the path. For example:
{
// more definitions
"scripts": {
// other scripts
"getPax8Products": "<filepath>",
// more scripts
},
// more definitions
}
In this case, you need to:
Add the following lines in the very beggining of the script
#!/usr/bin/env node
'use strict';
Give the file execution permission
# in UNIX based
chmod +x <filepath>
You also can modify the package.json and add the node command. However, you need to be aware that NPM will run in the script's directory:
{
// more definitions
"scripts": {
// other scripts
"getPax8Products": "node <filepath>",
// more scripts
},
// more definitions
}

For Deploying with Docker:
make sure /node_modules is deleted or added to dockerignorefile
make sure /dist is deleted or added to dockerignorefile
the problem was solved for me by deleting both files
and build them in the container

For me, I had not installed my dependencies. node_modules did not exist, but I had jest installed globally apparently. Running npm ci and then running npm test solved my issue.

npm install lite-server --save-dev
packages.json:
"scripts": {
"dev": "lite-server",
},
"devDependencies": {
"lite-server": "^2.6.1"
}
npm run dev

I stuck with same issue when tried to install packages into AWS Sagemaker instance
The issue coming because NPM by default install new global packages into ~/.npm-global
When you run npm install -g by root, npm is try to install package into /root/.npm-global/..., and stuck with access denied.
Simply workaround to re-config global folder for npm.
(https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally)
Here is example of install obj2gltf
mkdir /npm-global
npm config set prefix '/npm-global'
export PATH=/npm-global/bin:$PATH
npm install -g obj2gltf

I had that error too and tried the above solutions without any change. My error was caused because I had Windows (11) with a WSL and NVM installed on both operating systems. I had to uninstall NVM on my Windows to resolve the conflicts.
I think if you develop in your WSL and have a resource installed on both operating systems, a dependency might point to the wrong operating system with the resource (in my case to the NVM on Windows). The WSL user didn't have sufficient permissions to perform any execution on the Windows machine, which lead to the error.

you need root user permission, just add sudo keyword before the command and write your password
sudo npm install -g pngquant-bin

Try to install node at project folder
npm install node

Related

node-gyp 5 on Windows: Cannot find npm\node_modules\node-gyp\bin\node-gyp.js

Running npm 6.11.3, node-gyp 5.0.3, VS2019 on Windows 10 v1903, getting this error:
Cannot find module %AppData%\npm\node_modules\node-gyp\bin\node-gyp.js (where %AppData% is expanded to the actual user-specific path).
The error only happens if the build is invoked via npm, i.e.:
npm run build
The package.json file scripts section:
"scripts": {
...
"build": "node-gyp build",
}
If node-gyp build is invoked manually outside npm context, the error is gone.
How do I get rid of the error and still use npm scripts for making builds?
Figured it out.
After upgrading to node-gyp 5 on a Windows 10 build system, I started getting the infamous Error: Cannot find module ... npm\node_modules\node-gyp\bin\node-gyp.js, caused by node_modules\npm-lifecycle\node-gyp-bin being pushed on top of my PATH by npm, exactly as described here.
None of the existing remedies I've found and tried could solve this issue for me, including installing the latest windows-build-tools. Here's exactly what I tried, in the following order:
manually clean up the mess and duplicates in System PATH and User PATH environment vars
reboot
choco unistall nodejs
rd /s %AppData%\npm\
rd /s %AppData%\npm\
choco install nodejs
npm install -g npm#latest
npm install -g node-gyp#latest
npm install -g typescript#latest
I was still getting the missing node-gyp.js error. What did help was to properly set npm config set node_gyp to point to the correct node-gyp.js, as suggested here. Yet somehow the script from that thread didn't work properly for me (as well some other PowerShell/Batch scripts I tried).
Eventually, I've come up with the following PowerShell 6 one-liner that did the trick for me:
pwsh -Command npm config set node_gyp "`u{22}$(Join-Path $(npm root -g) -ChildPath 'node-gyp\bin\node-gyp.js')`u{22}"
Hope this helps others and future-me. I'd still recommend going through the above bullet list for clean troubleshooting.

Error while using create-react-app - ENOENT

New Node & React user here. I'm following the React tutorial but run into a problem on my Windows 10 machine:
C:\Users\Wout>create-react-app my-app
Creating a new React app in C:\Users\Wout\my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
npm ERR! path C:\Users\Wout\my-app\node_modules\abab
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\Wout\my-app\node_modules\abab' -> 'C:\Users\Wout\my-app\node_modules\.abab.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Wout\AppData\Roaming\npm-cache\_logs\2018-03-14T15_21_11_867Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... node_modules
Deleting generated file... package.json
Deleting my-app / from C:\Users\Wout
Done.
Things I've tried so far:
Reinstall Node.js (v8.10.0, npm 5.6.0)
Disabling Adobe creative cloud sync & related processes (these were spawning node.exe processes)
Running CMD in admin
Run the command from VS Code Powershell
Closing Visual Studio Code before executing the command
Run the command with npx
Rebooted the system several times
Running the command from the user folder as well as other drives
Running the Typescript version: create-react-app my-app --scripts-version=react-scripts-ts
It's all quite strange to me, since on Mac OS X the command executes without issues. I also can't seem to find other people with the same problem.
For what it's worth, it always stops after this "finalizing abab" package step.
I have an installation of XAMPP running an Apache and MySQL service, don't know if that has anything to do with it. I don't think so since I'm not even running the app yet, plus the server runs on port 3000 anyway.
I eventually solved it by closing as many extra processes as possible. Will try to find out which process was interfering with the command.
Edit: Ding ding ding! It was MalwareBytes! The "realtime protection 30-day trial" had restarted after an update and it was screwing with the filesystem.
I also just installed MalWareBytes, and I get the same error. I tried running create-react-app from the CLI as administrator, and while it was running I read your solution, and so I shut down MalWareBytes as the installation was in progress.
It worked, but I don't know if that is because I ran as administrator, or because I shut down MalWareBytes.
But for anyone having this problem, you could also try running your command prompt/powershell with administrator rights.
try running the command from the project directory...
worked for me.
i ran the command from the parent of the project directory for example:
reactApp/hellowworld
run from helloworle directory instead...
In case you have just install the create-react-app command , try to run the command from a new terminal . (re-open another tab).

nodejs - failing to install contextify via npm

Getting errors regarding "node-gyp rebuild" but can't seem to figure out why?
Full error: http://pastebin.com/HJ4z6tie
Perhaps, this links and solutions will be useful for you:
1) https://github.com/hideo55/node-murmurhash3/issues/4
Problem:
When I run the command sudo npm link your NPM is failing.
Solution:
when I use --unsafe-perm=true this NPM works.
2) https://github.com/npm/npm/wiki/Troubleshooting#permission-error
Permission Error
npm ERR! code EPERM
npm ERR! code EACCES
Fix the permissions of your cache with sudo chown -R $(whoami) "$HOME/.npm".
Try again with sudo. e.g. sudo npm install express -g. (You'll probably need to fix cache permissions afterwards, as above).
Reinstall node so it doesn't require sudo.
The EACCES error code means that the process does not have permissions to read/write in the target directory/file. As is common with package managers, this usualy means the module could not be installed to target directory.
This may be fixed by running the command as super user (sudo ...), but preferrably you would just fix the file permissions so that the account that runs the command has necessary permissions to the target directory.
As a side-note, the EACCES error comes from the great Linux itself - see the list of other error codes (or run man errno) one might encounter.
Define environment variable NODE_PATH as such :
export NODE_PARENT=${HOME}/node-v0.12.0
export PATH=${NODE_PARENT}/bin:${PATH} # so executables are found
export NODE_PATH=${NODE_PARENT}/lib/node_modules # so node can find modules
./configure --prefix=${NODE_PARENT}
do this when installing Node from source ... which gives you node and npm
and will avoid all such permission errors ... then install modules as yourself ... no need for root
npm install -g some-global-module

NPM cannot install dependencies - Attempt to unlock something which hasn't been locked

I've been trying to run an npm install on my package.json file, but I'm having a lot of trouble. It keeps saying "Error: Attempt to unlock XXX, which hasn't been locked" on all my dependences. Here's one of them:
Error: Attempt to unlock tbd#~0.6.4, which hasn't been locked
at unlock (/usr/local/lib/node_modules/npm/lib/cache.js:1304:11)
at cb (/usr/local/lib/node_modules/npm/lib/cache.js:646:5)
at /usr/local/lib/node_modules/npm/lib/cache.js:655:20
at /usr/local/lib/node_modules/npm/lib/cache.js:1290:7
at /usr/local/lib/node_modules/npm/node_modules/lockfile/lockfile.js:167:38
at OpenReq.Req.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:144:5)
at OpenReq.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:64:22)
at Object.oncomplete (fs.js:107:15)
If I try to run it as sudo, it seems to get further and start installing some packages, but some new errors popup instead:
> chokidar#0.8.1 postinstall /Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/chokidar
> node setup-deps.js
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
node.js:811
var cwd = process.cwd();
^
Error: EACCES, permission denied
at Function.startup.resolveArgv0 (node.js:811:23)
at startup (node.js:58:13)
at node.js:902:3
npm ERR! error rolling back Error: ENOTEMPTY, rmdir '/Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/q'
npm ERR! error rolling back karma#0.10.9 { [Error: ENOTEMPTY, rmdir '/Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/q']
npm ERR! error rolling back errno: 53,
npm ERR! error rolling back code: 'ENOTEMPTY',
npm ERR! error rolling back path: '/Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/q' }
npm ERR! Error: ENOENT, chown '/Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/socket.io/lib/socket.io.js'
I recently updated my node and npm installations. So maybe that has something to do with it. Also, most of my development has been at the office and today I'm working over VPN, so maybe that has something to do with it too.
Any ideas?
As per photusenigma at: https://github.com/npm/npm/issues/4815
Run these commands in a terminal window (note - DON'T replace the $USER part...thats a linux command to get your user!):
sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/local/lib/node_modules
...and...if you're on a mac (like I am), and still see errors after running these commands, then run this last one and you should be good. (Recommend you try testing before you do this one. I don't like changing the permissions on the ENTIRE /usr/local directory unless it really seems necessary!)
sudo chown -R $USER /usr/local
I worked with a co-worker this afternoon and figured out what the problem was. My ".npm" folder in my home directory was owned by the root user instead of myself. I'm not sure what happened to cause that. Maybe I installed node or npm as the root admin at one point. In any case I just ran sudo chown -R [username] .npm and I was finally able to run npm install commands from my projects again!
In my case the issue was invoking npm with a user that does not have a HOME directory, so for example the following command would fail:
sudo -u someUser npm install
The solution is to provide a HOME directory, where someUser has write access:
sudo -u someUser HOME=/some/directory npm install
Had the same issue and fixed it by changing the persmissions as per the accepted answer:
sudo chown -R $USER ~/.npm
However, the second command should be avoided as it downgrades the permissions of a system resource (sudo chown -R $USER /usr/local/lib/node_modules). Not a good idea.
For the record: "usr" in /usr/local stands for Unix System Resources.
None of this worked for me. I had to run literally as root by doing the following:
sudo su -
sudo npm install forever -g
Then the package installed on Linux Ubuntu 14.04.
The following command should fix permission issues:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
You can read about another officially recommended solutions here:
https://docs.npmjs.com/getting-started/fixing-npm-permissions
My solution:
sudo chown -R $USER /usr/local/lib/node_modules/NAMEOFMODULE
in my case was :
sudo chown -R $USER /usr/local/lib/node_modules/appium/
But I was getting the same problem, finally after
npm cache clean
it worked !
I had the same problem and tried to fix the permission/ownership of npm related files and directories for hours but had no luck with that.
Suddenly I found that I had ~/.npmrc file with cache entry pointing to a non-existing directory. Removed that cache property to use the default cache location and now it's solved.
Disclaimer
I am a Windows user. However, my team and I have come across a number of issues regarding npm installaion errors.
Problems
The following is a list of lessons learned and a possible radical solution that has always rescued us:
node_modules, the npm local installation directory becomes protected from modification by a shortcoming of the OS such as the inability to process paths longer than 255 characters.
If the folder is erased by means of a command line tool it may still appear as if the folder exists in the explorer that when trying to access it gives a number of permission errors.
Depending on your antivirus and/or local policy manager you may be able to create the node_modules folder and later relegated access or permissions to it resulting in a number of installation errors.
Enable npm logs to gain further insight into possible problems with:
npm install --loglevel verbose
Radical
Install rimraf globally
npm install rimraf -g
Run rimraf on node_modules:
rimraf yourDir/node_modules
Then try running:
npm install
Warning!
Or lack there of. Be extremely careful about what follows the command rimraf. There are no warnings, no prompts, there is nothing. It simply erases the directory from the phase of the earth clean, as if it was never there. Try it at your own risk.
for me, it was my proxy... and make sure to delete package-lock.json.
this worked for me on my mac / unix based system:
npm config rm proxy
npm config rm https-proxy
npm config delete proxy
npm config delete https-proxy
npm config --global rm proxy
npm config --global rm https-proxy
npm config set registry "http://registry.npmjs.org"
npm config set strict-ssl false
npm install
run: scutil --proxy
you should get dictionary list...
then get these values from that list:
HTTPProxy : 127.0.0.1 HTTPPort : 8118
then include them in this command:
npm config set proxy http://127.0.0.1:8119
then include this:
npm config set https-proxy https://123.0.0.1:8118
reference: https://www.sneppets.com/angular/how-to-make-npm-install-command-to-work-behind-proxy/

NPM global install "cannot find module"

I wrote a module which I published to npm a moment ago (https://npmjs.org/package/wisp)
So it installs fine from the command line:
$ npm i -g wisp
However, when I run it from the command line, I keep getting an error that optimist isn't installed:
$ wisp
Error: Cannot find module 'optimist'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/usr/local/lib/node_modules/wisp/wisp:12:10)
at Object.<anonymous> (/usr/local/lib/node_modules/wisp/wisp:96:4)
at Module._compile (module.js:449:26)
at Object.exports.run (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:68:25)
at compileScript (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:135:29)
at fs.stat.notSources.(anonymous function) (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:110:18)
However, I have specified in package.json as a dependancy:
{
"name": "wisp",
"author": "Brendan Scarvell <bscarvell#gmail.com>",
"version": "0.1.0",
"description": "Global nodejs file server",
"dependencies": {
"optimist": "~0.3.4"
},
"repository": "git://github.com/tehlulz/wisp",
"bin": {
"wisp" : "./wisp"
}
}
Does anyone know what to do to get this running? I know its to do with the bin part adding the executable to bin and the node_modules in that directory being empty. No idea how to resolve this.
For anyone else running into this, I had this problem due to my npm installing into a location that's not on my NODE_PATH.
[root#uberneek ~]# which npm
/opt/bin/npm
[root#uberneek ~]# which node
/opt/bin/node
[root#uberneek ~]# echo $NODE_PATH
My NODE_PATH was empty, and running npm install --global --verbose promised-io showed that it was installing into /opt/lib/node_modules/promised-io:
[root#uberneek ~]# npm install --global --verbose promised-io
npm info it worked if it ends with ok
npm verb cli [ '/opt/bin/node',
npm verb cli '/opt/bin/npm',
npm verb cli 'install',
npm verb cli '--global',
npm verb cli '--verbose',
npm verb cli 'promised-io' ]
npm info using npm#1.1.45
npm info using node#v0.8.4
[cut]
npm info build /opt/lib/node_modules/promised-io
npm verb from cache /opt/lib/node_modules/promised-io/package.json
npm verb linkStuff [ true, '/opt/lib/node_modules', true, '/opt/lib/node_modules' ]
[cut]
My script fails on require('promised-io/promise'):
[neek#uberneek project]$ node buildscripts/stringsmerge.js
module.js:340
throw err;
^
Error: Cannot find module 'promised-io/promise'
at Function.Module._resolveFilename (module.js:338:15)
I probably installed node and npm from source using configure --prefix=/opt. I've no idea why this has made them incapable of finding installed modules. The fix for now is to point NODE_PATH at the right directory:
export NODE_PATH=/opt/lib/node_modules
My require('promised-io/promise') now succeeds.
add this to beginning of prog(mac):
module.paths.push('/usr/local/lib/node_modules');
By default node does not look inside the /usr/local/lib/node_module for loading global modules.
Refer the module loading explained in http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
So either you have to
1)add the /usr/local/lib/node_module to NODE_PATH and export it
or
2)copy the installed node modules to /usr/local/lib/node .
(As explained in the link for loading module node will search in this path and will work)
The following generic fix would for any module. For example with request-promise.
Replace
npm install request-promise --global
With
npm install request-promise --cli
worked (source) and also for globals and inherits
Also, try setting the environment variable
NODE_PATH=%AppData%\npm\node_modules
For some (like me) that nothing else worked, try this:
brew cleanup
brew link node
brew uninstall node
brew install node
Hope it helps someone :)
I got the "optimist" module error and I just did "npm install" to resolve it. went past that error.
https://github.com/mbloch/mapshaper/issues/12
On windows if you just did a clean install and you get this you need blow away your npm cache in \AppData\Roaming
$ vim /etc/profile.d/nodejs.sh
export NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
For Windows, from Nodejs cannot find installed module on Windows? what worked for me is running npm link as in
npm link wisp
I did this in simple way...
Un-Install node from control panel [Windows 7]
Install node again
Install protractor
npm install --global --verbose protractor
Update web driver manager.
works fine for me.
Hope this helps you....
I got this error Error: Cannot find module 'number-is-nan' whereas the module actually exists. It was due to a bad/incomplete Node.js installation.
For Windows , as other answers suggest it, you need a clean Node installation :
Uninstall Node.js
Delete the two folders npm and npm_cache in C:\Users\user\AppData\Roaming
Restart Windows and install Node.js
Run npm initor (npm init --yes for default config)
Set the Windows environment variable for NODE_PATH. This path is where your packages are installed. It's probably something likeNODE_PATH = C:\Users\user\node_modules or C:\Users\user\AppData\Roaming\npm\node_modules
Start a new cmd console and npm should work fine
Note :
Try the last points before reinstalling Node.js, it could save you some time and avoid to re-install all your packages.
For Mac User's It's Best use the manual installation:
To minimize the chance of permissions errors, you can configure npm to
use a different directory. In this example, it will be a hidden
directory on your home folder.
Back-up your computer before you start.
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
Instead of steps 2-4, you can use the corresponding ENV variable (e.g.
if you don't want to modify ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global
Reference : https://docs.npmjs.com/getting-started/fixing-npm-permissions
I have just met this problem of the axios module.
Then I tried this: run rm -rf node_modules and yarn.
And it works.
Had the same problem on one of the test servers running Ubuntu under root. Then created a new user using useradd -m myuser and installed everything (nvm, node, packages) as myuser. Now it's working fine.
In my case both node and npm were in same path (/usr/bin). The NODE_PATH was empty, so the npm placed the global modules into /usr/lib/node_modules where require(...) successfully find them.
The only exception was the npm module, which came with the nodejs package. Since I'm using 64 bit system, it was placed into /usr/lib64/node_modules. This is not where require(...) searches in case of empty NODE_PATH and node started from /usr/bin. So I had two options:
link /usr/lib64/node_modules/npm to /usr/lib/node_modules/npm
move modules from /usr/lib/node_modules/* to /usr/lib64/node_modules/ and set NODE_PATH=/usr/lib64/node_modules
Both worked. I'm using OpenSUSE 42.1 and the nodejs package from updates repository. Version is 4.4.5.
I had the same error as the OP, but digging through the logs I could see sh: node: command not found.
It turns out that the /usr/bin/node program (symlink) is no longer installed with apt install nodejs. Once symlinked /usr/bin/node' tonodejs,npm install -g #angular/cli` succeeded.
The proper way to install this on debian is apt install nodejs-legacy.
I had to add C:\Users\{Username}\AppData\Roaming\npm to my env variables and then i could install stuff.
Faced the same issue and got it resolved by adding the below line in my zshrc.
Based on your shell you can try adding in your rc file, for bash and zsh - bashrc/zshrc files present in your home location.
export NODE_PATH="/usr/local/lib/node_modules"
To directly add in zshrc file, run this command
echo 'export NODE_PATH="/usr/local/lib/node_modules"' >> ~/.zshrc
Alpine / Containerization
As mentioned elsewhere, the solution is to bake into your image,
NODE_PATH=/usr/local/lib/node_modules/
I've also opened up an issue upstream with npm apk so this gets set

Resources