25

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! }
EzeTeja
  • 1,125
  • 1
  • 13
  • 21

13 Answers13

50

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.

EzeTeja
  • 1,125
  • 1
  • 13
  • 21
5

Upgrading to WSL2 from WSL1 helped me fix the issue.

To check the version of WSL run this command in powershell.

wsl -l -v

To set version to 2

wsl --set-version <distro name> 2
Anonymous
  • 49
  • 1
  • 1
3

you can fix that error by allowing unsafe perms

npm config set unsafe-perm=true
npm install

https://github.com/microsoft/WSL/issues/14#issuecomment-207504657

1

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
1

To solve this I had to do the following

  • Close vsCode and any other app that is accessing the worskspace folder
  • Remove the node_module folder (not just the contents)
  • from WSL
    $sudo chown <yourUser> package-lock.json
    $rmdir node_modules
    

Finally run $npm install from WSL (Ubuntu)

Mauricio Gracia Gutierrez
  • 10,288
  • 6
  • 68
  • 99
0
  • 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
Yashwanth Kumar
  • 341
  • 3
  • 6
0

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
CallMarl
  • 524
  • 4
  • 15
0

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/

Shravan kp
  • 109
  • 1
  • 3
0

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

every other npm install works

Alkari
  • 116
  • 2
  • 11
0

My issue seemed to be WSL having issues renaming the node_modules directory

I tried everything but the only thing that fixed it for me was the following:

  • Make sure Ubuntu is running (just have the Ubuntu CLI open)
  • Open windows file-explorer
  • Type \\wsl$ into the search-bar in explorer and open the Ubuntu-directory (your Ubuntu directory will not be displayed in explorer unless you have Ubuntu up and running somewhere in the background)
  • Navigate to your project via explorer
  • Delete node_modules manually (shift + delete)
  • Close everything (VScode, Ubuntu, any CLI connected to WSL)
  • Open Ubuntu again and navigate to your project (cd projectName) and type "code ." to open an instance of your project in VScode
  • Open a new terminal instance inside VScode and type "npm install"

Hope it helps

0

I fixed it with the File Watcher setting, I installed the extension I needed and then changed the setting back to the default value as it can degrade performance.

Go to File > Settings and search for "Polling" and tick the checkbox. The config is called: "Remote.WSL > File Watcher: Polling"

Or you can change it from the settings.json file:

In WSL (WSL1), there is a limitation where it is not possible to rename a non-empty folder from VS Code. To work around this issue, you can tell VS Code to “poll” for file system changes rather than apply a lock to the folder.

In your user settings.json, add:

"remote.WSL.fileWatcher.polling": true

Polling is resource heavy, so it is not turned on by default. You can also tune how often VS Code polls using the remote.WSL.fileWatcher.pollingInterval setting, which is by default every 5 seconds.

You will need to reload VS Code (Developer: Reload Window from the Command Palette (F1)) for these settings to take effect.

Source: https://devblogs.microsoft.com/commandline/tips-and-tricks-for-linux-development-with-wsl-and-visual-studio-code/#workaround-for-renaming-folders

Tomás Cot
  • 992
  • 1
  • 8
  • 18
0

Sometimes its showing this error because you are not the owner of that folder you're working on, for example when you copy a project folder from your windows file system to WSL folders structure. You need to set the owner of current directory to the user you're logged in with, like this:

sudo chown <user-name> .

Then you can work with the files on that folder

Mahmoud_Mehri
  • 1,643
  • 2
  • 20
  • 38
-2

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

Gustavo Jose
  • 57
  • 1
  • 2
  • While this may work for some people it generally shouldn't be necessary and isn't recommended, for me this didn't work, even though it the error reports permissions I believe it isn't to do with that, for me upgrading from WSL 1 to WSL 2 fixed the issue. – Hobnob Feb 23 '23 at 14:11
  • start with **chwon -R \`whoami\` [folder]** instead of jumping strait to trip 7s – Jacksonkr Aug 31 '23 at 16:03