npm WARN checkPermissions Missing write access - node.js

I have been trying to fix the issue of running node without using sudo on my mac but I keep getting this message:
npm WARN checkPermissions Missing write access to /Users/myuser/.npm-packages/lib/node_modules/npm
And still find no fix for that. Has anyone seen this issue before?

This is a known bug, even now with npm 6.14 available.
Here it is a link to npm.community.
You can give current user permission to access node_modules using this in terminal:
sudo chown -R $USER /usr/local/lib/node_modules
and then npm install.

OK I found what was wrong.
I tried to open the /Users/myuser/.npm-packages/lib/node_modules/npm folder on finder to see if I could change the folder permissions but it seemed like the npm folder was pointing to some non-existing directory.
So I removed the npm symbolic link and created a new empty npm folder and everything seems to be working now.

Works for me on Ubuntu:
sudo chown -R $USER /usr/local

Related

How to give vscode permission to mkdir without using it as sudo su, I'm using mint 20

I recently installed mint and I'm doing some tests on VSCode, I'm a long time windows user but I ran into a problem. I program nodejs and when I run npm install, it gives permission access errors and I want to know if there's a way around it that isn't running vscode as super user.
Error:
npm WARN checkPermissions Missing write access to /home/dotta/Documents/Udemy Codes/surf_shop/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /home/dotta/Documents/Udemy Codes/surf_shop/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/home/dotta/Documents/Udemy Codes/surf_shop/node_modules'
Run the following
ls -la /home/dotta/Documents/Udemy\ Codes/surf_shop you will see that its owned by root, why because you run sudo npm install at some point.
To fix:
Delete node_modules:
sudo rm -rf /home/dotta/Documents/Udemy\ Codes/surf_shop/node_modules
Then fix ownership permissions:
sudo chown dotta:dotta -R /home/dotta/Documents/Udemy\ Codes
Then you will be able to npm install, don't use sudo to install or make directories else when you want to do stuff as a normal user you wont own the directory or file.
Also dont start vs-code as root i.e: sudo code . else any point within vs-code its making folders/files as root.
...
sidenote, avoid spaces in folders or filenames.
you need to give VSCODE admin right,go to VSCODE icon click right button -> properties -> advanced -> grant admin right and close all old terminals on VSCODE ,open a new one and enjoy !

NPM/Cordova permissions Error: EACCES: permission denied, scandir

When I run cordova plugin add cordova-plugin-geolocation I receive the following error. I have tried enable 777 on this folder, setting myself as the owner etc. In these circumstances I'm not allowed to use sudo, but am confident if I could that would solve the problem.
Failed to install 'cordova-plugin-geolocation': Error: EACCES: permission denied, scandir '/Users/username/documents/core/myapp/app/platforms/ios/build/device/libCordova.a'
at Error (native)
at Object.fs.readdirSync (fs.js:952:18)
at GlobSync._readdir (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:275:41)
at GlobSync._readdirInGlobStar (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:254:20)
at GlobSync._readdir (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:263:17)
at GlobSync._processReaddir (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:135:22)
at GlobSync._process (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:130:10)
at GlobSync._processGlobStar (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:360:10)
at GlobSync._process (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:128:10)
at GlobSync._processGlobStar (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:363:10)
Error: EACCES: permission denied, scandir '/Users/username/documents/core/myapp/app/platforms/ios/build/device/libCordova.a'
NPM issue's
You can fix this problem using one of three options:
1).Change the permission to npm's default directory.
2).Change npm's default directory to another directory.
3).Install node with a package manager that takes care of this for you.
You should back-up your computer before moving forward.
Option 1: Change the permission to npm's default directory
1).Find the path to npm's directory:
npm config get prefix
For many systems, this will be /usr/local.
WARNING: If the displayed path is just /usr, switch to Option 2 or you will mess up your permissions.
2).Change the owner of npm's directories to the name of the current user (your username!):
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
This changes the permissions of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).
Option 2: Change npm's default directory to another directory
There are times when you do not want to change ownership of the default directory that npm uses (i.e. /usr) as this could cause some problems, for example if you are sharing the system with other users.
Instead, you can configure npm to use a different directory altogether. In our case, this will be a hidden directory in our home folder.
1).Make a directory for global installations:
mkdir ~/.npm-global
2).Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
3).Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
4).Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
nstead of steps 2-4 you can also use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global
Option 3: Use a package manager that takes care of this for you.
If you're doing a fresh install of node on Mac OS you can avoid this problem altogether by using the Homebrew package manager. Homebrew sets things up out of the box with the correct permission.
brew install node
For Mac users, if you are looking for a quick answer, you can edit the permissions of the .npm folder located at /Users/$(whoami)/.npm.
Go to .npm parent folder (to prevent running the 2nd command in the wrong place).
$ cd /Users/$(whoami)
Run chmod to change the permissions of the .npm folder.
$ sudo chmod -R 777 .npm/*
That's how I solved on my case.
In case anyone else arrives with a Mac cordova environment that has sudo'd itself beyond repair, this was my only solution (after a lot of pain):
backup everything
remove all cordova platforms (WARNING: this will wreck anything custom you've done within a platform, thus the backup)
uninstall cordova globally
uninstall npm; I just used the basic command from their site: sudo npm uninstall npm -g
install NVM
through that, install Node long-term-stable
install cordova (no more sudo required)
take permissions of your project directory (I did my whole user directory recursively)
add your platforms
diff back in any of your customizations
find a comfortable chair and drink scotch

gyp WARN EACCES user "root" does not have permission to access the dev dir

Trying to
sudo npm install protractor -g
and the same notorious error/warning again (googled to no avail):
gyp WARN EACCES user "root" does not have permission to access the dev dir "/Users/dmitrizaitsev/.node-gyp/0.12.0"
What seems to happen is that node version 0.12.0 is downloaded and rebuilt, again and again during the same installation, despite of being the current node version on my machine:
node -v
v0.12.0
Questions:
The directory "/Users/dmitrizaitsev/.node-gyp/0.12.0" is actually missing! Why such a misleading message?
Why was this directory not created neither during the node v0.12.0 nor during the previous successful rebuild with node-gyp?
(Obviously) How can I prevent this from happening?
I run Mac OSX 10.8.5 if that is of any importance.
UPDATE. There is a better way - changing npm's default global directory to user sub-directory to which you already have correct permissions, so no need to mess with system file's permissions or ownership in first place.
As recommended in
https://docs.npmjs.com/getting-started/fixing-npm-permissions:
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 (or ~/.bash_profile etc) file and add this line (at the end of the file):
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.profile
or source ~/.bash_profile
See also Sindre Sorhus's guide on the topic: https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md
Have now figured what was wrong:
The directory had wrong permissions - it was not writable (which would have been a better error message than "accessible").
And because it was not writable, a temporary directory was used and deleted after every use, which is why the whole download had to run again and again.
The solution is to set user permissions with
sudo chown -R $USER <directory>
and never sudo npm again.
It seems whenever you run sudo npm, all subdirectories created get wrong permissions, which will lead to problems later on.
See here for more details.
Try with:
sudo npm install -g module --unsafe-perm
That's because you do not have a folder in this directory "/Users/dmitrizaitsev/.node-gyp/0.12.0".
Just create a new folder named 0.12.0 which is the version number of your node
It will fix the problem.

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/

Resources