EACCESS error when installing packages on WSL

Viewed 17460

I'm getting this error trying to NPM INSTALL packages on WSL from VS Code.

npm ERR! Error: EACCES: permission denied, rename '/mnt/d/DEVRepo/PWS/functions/node_modules/cssstyle' -> '/mnt/d/DEVRepo/PWS/functions/node_modules/.cssstyle.DELETE'
npm ERR!  [OperationalError: EACCES: permission denied, rename '/mnt/d/DEVRepo/PWS/functions/node_modules/cssstyle' -> '/mnt/d/DEVRepo/PWS/functions/node_modules/.cssstyle.DELETE'] {     
npm ERR!   cause: [Error: EACCES: permission denied, rename '/mnt/d/DEVRepo/PWS/functions/node_modules/cssstyle' -> '/mnt/d/DEVRepo/PWS/functions/node_modules/.cssstyle.DELETE'] {        
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'rename',
npm ERR!     path: '/mnt/d/DEVRepo/PWS/functions/node_modules/cssstyle',
npm ERR!     dest: '/mnt/d/DEVRepo/PWS/functions/node_modules/.cssstyle.DELETE'
npm ERR!   },
npm ERR!   stack: "Error: EACCES: permission denied, rename '/mnt/d/DEVRepo/PWS/functions/node_modules/cssstyle' -> '/mnt/d/DEVRepo/PWS/functions/node_modules/.cssstyle.DELETE'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/mnt/d/DEVRepo/PWS/functions/node_modules/cssstyle',
npm ERR!   dest: '/mnt/d/DEVRepo/PWS/functions/node_modules/.cssstyle.DELETE',
npm ERR!   parent: 'functions'
npm ERR! }
8 Answers

The problem is that VSCode WSL extension locks files and that generates the error.

The solution is to close the WSL connection on VSCode o just close the whole IDE and run the npm install command again.

  • Donwload "package-version.vsix" online
  • rename "package-version.vsix" to "package-version.zip"
  • create directory /home/user/.vscode-server/extensions/package-version
  • extract the contents of to "package-version.zip"
  • move contents of "extension" folder of the extracted zip archive to /home/user/.vscode-server/extensions/package-version
  • connect to wsl, now it will be installed

Finally find way to upgrade npm by mixing multiple answer :

  • Run powershell then change version of wsl distribution
# List available distribution
PS C:\Users\CallMarl> wsl.exe -l
Debian (par défaut)
# set version to 2
PS C:\Users\CallMarl> wsl.exe --set-version Debian 2
  • Run wsl then install lastest-version
PS C:\Users\CallMarl> wsl.exe -d Debian
callmarl@LAPTOP ~ % sudo npm install -g npm@latest
  • Then check npm version
callmarl@LAPTOP ~ % npm -v
7.20.3
  • For some reason you can rollback to WSL 1 by running in powershell wsl.exe --set-version Debian 1

Since wsl doesn't allow write operation on /usr/lib/node_modules without sudo, we can remap the location where node_modules are installed using below commands.

mkdir ~/.npm-new
npm config set prefix '~/.npm-new'
export PATH=~/.npm-new/bin:$PATH
source ~/.profile

https://cmatskas.com/resolve-npm-access-denied-errors/

I had this same error/issue when running

npm install -g elm-format

WSL version was Ubuntu 2 Cache was fine. Closed VSCode. SAME ERROR!

What worked for me was using SUDO in front i.e.

sudo npm install -g elm-format

In my case node modules was the problem, so I deleted it and ran npm install

every other npm install works

Check folder permissions if you have 777 example: chmod -R 777 myfolder

Related