npm cannot install packages, access denied to .npm cache folder - npm

When running npm install on a local project, I get this error:
npm ERR! Error: EACCES: permission denied. The operation was rejected by your operating system. It is likely you do not have the permissions to access this file as the current user
For unclear reasons, it seems that a global .npm folder is causing the troubles.
path /Users/erik/.npm/_cacache/index-v5/ab/a6/079836a3c186b5fd2d717a4
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open
npm ERR! Error: EACCES: permission denied
I tried forcing the install with sudo npm install but then I get these errors:
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js
Worst of all, it seems that npm is no longer working now, when executing any npm command I get this very weird error
npm -v
const path = i >= 0 ? args[i] : process.cwd(); Error: ENOENT: no such file or directory, uv_cwd
How can I fix these permission issues? Even locally I am not allowed to use npm install.

Related

converting existing puppeteer tests to playwright

Trying to convert my existing puppeteer test to playwright. The instruction here is not very clear. Has anyone able to do this successfully? What steps did you follow?
https://github.com/checkly/puppeteer-to-playwright#-getting-started
downloaded the repo. Tried running npm run convert -- -d my-puppeteer-script.js (changed test file name to cookies.js. I get this:
puppeteer-to-playwright#1.0.0 convert
> jscodeshift --run-in-band "-d" "cookies.js"
Skipping path cookies.js which does not exist.
No files selected, nothing to do.
All done.
Results:
0 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 0.002seconds
Tgebrehiwot4#C02FL3CBMD6R puppeteer-to-playwright % npm install -g jscodeshift
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/jscodeshift
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/jscodeshift'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/jscodeshift'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/jscodeshift'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Tgebrehiwot4/.npm/_logs/2022-10-27T17_55_03_898Z-debug-0.log
Tgebrehiwot4#C02FL3CBMD6R puppeteer-to-playwright %
[Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/jscodeshift']
This is a permission error, you need to check the folder/file permissions to ensure you have the necessary permissions to perform the actions it needs.
This question can help you how to change the permissions for a specific folder on Linux.

How can i install yeoman command line tool on ubuntu 20.04.1 LTS?

I tried installing yeoman command line tool in Ubuntu 20.04.1 LTS for ASP.NET Core web application development. After typing
npm install -g yo in terminal, i got an error.
Description of error is provided below.
npm WARN deprecated har-validator#5.1.5: this library is no longer supported
npm WARN deprecated cross-spawn-async#2.2.5: cross-spawn no longer requires a build toolchain, use it instead
npm WARN deprecated resolve-url#0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix#0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN checkPermissions Missing write access to /usr/local/lib
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib'
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib']
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, access \'/usr/local/lib\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/shashankshekhar/.npm/_logs/2020-12-21T11_02_14_859Z-debug.log```
The issue of EACCES errors on global module installation is so common that npm has an entire web page dedicated to solving just this issue.
Since you are installing yeoman, I imagine this is a development machine. In that case, your best bet is likely to install node/npm with a package manager like nvm.
One thing you don't want to do but that people will often suggest is running the npm command with sudo. People recommend this because it's easy. But if you do that, all the lifecycle scripts (e.g., postinstall) of the dependencies of whatever you are installing will also be run as root. That's potentially a lot of untrusted code running as root.

Missing write access when installing Vue CLI

For some reason I cannot run the vue cli and trying to reinstall using:
npm install -g #vue/cli
I get a string of
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/#vue/cli/node_modules/#apollographql/graphql-playground-html
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/#vue/cli/node_modules/#babel/core/node_modules/semver
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/#vue/cli/node_modules/#babel/helper-plugin-utils
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/#vue/cli/node_modules/#babel/parser
And then ending with
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules/#vue/cli/node_modules/#apollographql/graphql-playground-html
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/#vue/cli/node_modules/#apollographql/graphql-playground-html'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules/#vue/cli/node_modules/#apollographql/graphql-playground-html'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules/#vue/cli/node_modules/#apollographql/graphql-playground-html\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules/#vue/cli/node_modules/#apollographql/graphql-playground-html' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
I have tried changing the permissions of /usr/local/lib/node_modules and then changed the group to "staff" (which is the same as Python also in /lib. I don't think I can uninstall node without some serious problems everywhere I use that. Stuck and not sure how to install or get vue cli running.
I have just had the same issue, but solved it by adding "sudo" before it.
So, the new line would instead look like;
sudo npm install -g #vue/cli

I couldn't install npm on my mac. I got the following errors

I am getting following checkPermissions error related write access while doing npm install.
npm install
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minizlib
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/npm
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/npm/node_modules/tar/node_modules
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minizlib
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minizlib'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minizlib'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minizlib\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minizlib' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mac/.npm/_logs/2018-02-08T17_10_28_286Z-debug.log .
Please provide some reference or information.
Use sudo in front of your install command and enter your password when prompted. It installs NPM into the global space, which requires SUDO if you are not on the root account.
That is what this part of the error is telling you: "Please try running this command again as root/Administrator."
After you install npm, you will have issues with global packages.
Use this suggested way of resolving it. Better, secure & maintainable.
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
nano ~/.zprofile
# Add a line to add the new dir to path, eg:
# PATH="~/.npm-global/bin":$PATH
# export PATH
source ~/.zprofile
Ref: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

Error when installing the express application generator

I recently installed node and express with the help of the mozilla tutorial. I am on the next step of installing the application generator, but when I run
npm install express-generator -g
in my terminal: I recieve the following errors:
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/adamgusky/.npm/_logs/2018-02-17T20_26_53_688Z-debug.log
I've been googling this topic for an hour now and I am very new to using the terminal for web applications (this is for a school project), so any help is appreciated.
I had a similar issue. The problem is that you aren't an administrator so you can't write to that folder. However it's considered a BAD IDEA to run sudo npm install. So what you need to do is to change the default install folder for npm global installation to one where you do have write permission.
See npm's documentation: https://docs.npmjs.com/getting-started/fixing-npm-permissions.
And also see this useful article on github: https://github.com/nodeschool/discussions/wiki/Installing-global-node-modules-(Linux-and-Mac)