NPM cannot install module, permission denied with mkdir - node.js

I am attempting to globally install the electron module with npm on OS X Sierra. When I run
sudo npm install electron -g
I get
/usr/local/bin/electron -> /usr/local/lib/node_modules/electron/cli.js
> electron#1.7.5 postinstall /usr/local/lib/node_modules/electron
> node install.js
/usr/local/lib/node_modules/electron/install.js:48
throw err
^
Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/electron/dist'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electron#1.7.5 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the electron#1.7.5 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! /Users/ianwise/.npm/_logs/2017-08-10T22_16_42_927Z-debug.log
The problem seems to be a permission denied when npm runs mkdir... But I'm running this with sudo, so why is this a problem?

I think you're running as root. run the following command.
npm config set unsafe-perm true
sudo npm install electron -g

I had exactly the same issue with electron.
Assuming you have checked that the relevant directories are writable with:
$ ls -l
In the end I tried without sudo and it worked...!
$ npm install electron -g
The process completed with a message saying:
npm notice created a lockfile as package-lock.json. You should commit this file.
I just deleted the package-lock.json file
For me, the process also completed with a message saying:
npm update check failed
I followed the instructions at Ubuntu: npm update failed to fix this

Related

updating node and npm from npm 6 to 8 and node 14 to 16 or 18 on a react native project , fails on ENOENT

Getting an error after running npm install,
It seems that npm is not pathed right for this file or something is cached?
I'm using homebrew and nvm to switch between versions, but the only version that works is node 14 and npm 6.
Need to install the following packages:
pod#0.9.0
Ok to proceed? (y) y
npm ERR! syscall chmod
npm ERR! path /Users/me/.npm/_npx/a0ca5f5666585aa2/node_modules/pod/node_modules/pm2/bin/pm2
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, chmod '/Users/me/.npm/_npx/a0ca5f5666585aa2/node_modules/pod/node_modules/pm2/bin/pm2'
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! /Users/me/.npm/_logs/2022-08-04T19_23_48_147Z-debug-0.log
npm ERR! code 254
npm ERR! path /Users/me/repos/MyApp/MyMobileApp
npm ERR! command failed
npm ERR! command sh /var/folders/d2/rdhvx2fd24vbsfrtf3lddq9m0000gq/T/postinstall-a0c95179.sh
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/me/.npm/_logs/2022-08-04T19_23_45_192Z-debug-0.log
```. i get User defaults from command line:
IDEPackageSupportUseBuiltinSCM = YES
error: Could not delete `/Users/me/repositories/MyApp/ios/build` because it was not created by the build system.
note: To mark this directory as deletable by the build system, run `xattr -w com.apple.xcode.CreatedByBuildSystem true /Users/me/repositories/MyApp/ios/build` when it is created.
error: Could not delete `/Users/me/repositories/MyApp/ios/build` because it was not created by the build system.
note: To mark this directory as deletable by the build system, run `xattr -w com.apple.xcode.CreatedByBuildSystem true /Users/me/repositories/MyApp/ios/build` when it is created.
** CLEAN FAILED **
Is now something that happens when I run xcodebuild -alltargets clean
This may be due to cache. Try below step and check if it works
Run rm -rf ~/.npm
Run npm cache clean --force
Remove node_modules (run rm -rf node_modules)
Remove package-lock.json (run rm -rf package-lock.json)
It happens when npm install conflict with peer dependencies
--legacy-peer-deps that ignores all peer dependencies when installing.
So the best approch is to use --legacy-peer-deps
npm install --legacy-peer-deps

What is the meaning of this error (protobufjs#6.11.2 postinstall: `node scripts/postinstall`)?

Hi i was installing firebase on the ubuntu console with npm install --save firebase
and got this error below in the installation process,
I tried to install npm install protobufjs#6.11.2 to try to get rid of the error but it did not work.
What is the meaning of the error?
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! protobufjs#6.11.2 postinstall: `node scripts/postinstall`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the protobufjs#6.11.2 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm attempts not to run the protobuff postinstall script as root and when you are trying to run it as a root using "sudo" command npm will try to prevent it. So you need to use --unsafe-perm flag while installing. So the full command will look like
sudo npm install --unsafe-perm -g firebase
I am not sure why this error occurs but my understanding is that it is related to some sort of permission issue.
You can solve this error by prefix Sudo
sudo npm install --save firebas

I have error for install electron on fedora 30

Hello i have this error if i try to install electron on my fedora 30
[luisjustin#localhost ~]$ sudo su
[sudo] password for luisjustin:
[root#localhost luisjustin]# npm install -g electron
/usr/bin/electron -> /usr/lib/node_modules/electron/cli.js
> electron#5.0.2 postinstall /usr/lib/node_modules/electron
> node install.js
/usr/lib/node_modules/electron/install.js:49
throw err
^
Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/electron/.electron'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electron#5.0.2 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the electron#5.0.2 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/2019-05-30T01_21_04_805Z-debug.log
[root#localhost luisjustin]#
the log in this link: https://pastebin.com/q3dSCQVg
There seems to be an issue with permissions on your machine (/usr/lib directory requires root access). What I suggest you to try is to change the default directory where NPM is installing packages globally. Then you can try to run the installation without root access.
Try this:
On the command line, in your home directory, create a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
In your preferred text editor, open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.profile
To test your new configuration, install a package globally without using sudo:
npm install -g electron
Courtesy:
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

NPM permission error while installing

i am trying to install yeoman on my server but for some reason do i keep getting a permission denied error.
$npm install -g yo
/root/.node/bin/yo -> /root/.node/lib/node_modules/yo/cli.js
> yo#1.3.3 postinstall /root/.node/lib/node_modules/yo
> yodoctor
sh: 1: yodoctor: Permission denied
npm ERR! yo#1.3.3 postinstall: `yodoctor`
npm ERR! Exit status 127
npm ERR!
npm ERR! Failed at the yo#1.3.3 postinstall script.
npm ERR! This is most likely a problem with the yo package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! yodoctor
npm ERR! You can get their info via:
npm ERR! npm owner ls yo
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.13.0-37-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "yo"
npm ERR! cwd /root
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR! not ok code 0
i have tried to reinstall ubuntu (14.04) but nothing works.
I think Shantaru is right, you need to do it with sudo.
Try this
sudo npm uninstall -g yo
sudo npm cache clean
sudo npm install -g yo
I have a similar problem weeks ago and that works.
Edit: If that didn't work, do this before:
npm config set unsafe-perm true
You need to have root permission to install this so try
"sudo npm install -g yo" instead of "npm install -g yo"
I had the same issue and tried running the install using 'sudo npm install -g yo' but it still failed. I couldn't get away from the fact that the error message still said 'sh: 1: yodoctor: Permission denied', indicating a permissions issue. I therefore tried completely changing to the root user using 'sudo su' and THEN running 'npm install -g yo'. This worked for me.
If, like me, when running the install that way you encounter other errors, it could be because you need to upgrade npm first (run 'npm install -g npm' to do that). It could also be because you have yo partially installed from your previous attempts and that's causing issues. Therefore you can try removing it first using 'npm remove -g yo' (still as root user) and then installing it again using 'npm install -g yo'.
Hope this helps someone out there.
To avoid permission errors, install node with nvm.
See the detailed solution here:
npm install g less does not work

Trouble installing tower module - ws module crashes

I'm new to node.js and I have installed it by running the installation from the node website. I've had a play installing packages globally (e.g. should) but now I'm trying to install the tower module on my Mac, like so:
sudo npm install tower -g
It install a bunch of stuff and then crashes, with output
npm http 304 https://registry.npmjs.org/tinycolor
npm http 304 https://registry.npmjs.org/zeparser/0.0.5
> ws#0.4.20 install /usr/local/lib/node_modules/tower/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
> node install.js
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
node.js:520
var cwd = process.cwd();
^
Error: EACCES, permission denied
at Function.startup.resolveArgv0 (node.js:520:23)
at startup (node.js:54:13)
at node.js:611:3
npm ERR! ws#0.4.20 install: `node install.js`
npm ERR! `sh "-c" "node install.js"` failed with 11
npm ERR!
npm ERR! Failed at the ws#0.4.20 install script.
npm ERR! This is most likely a problem with the ws package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node install.js
npm ERR! You can get their info via:
npm ERR! npm owner ls ws
npm ERR! There is likely additional logging output above.
If I read that correctly it's the ws (websockets?) module crashing.
In researching this problem a blog suggested I add the node path to my .bashrc so I have done that.
Any suggestions?
At this line:
ws#0.4.20 install /usr/local/lib/node_modules/tower/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
We see that ws is install in /usr/local/lib, I need root to write here no ?
I'm using linux, it's maybe not the case in mac...
You should use sudo npm install -g tower or install Node.js with nvm. Nvm cares that modules are install in your home, so you do not need sudo.
After much experimentation the only thing that worked for me was to enable the OSX root account, and then:
su
npm install -g tower
sudo did not work but su did.

Resources