我在尝试从VS Code到WSL上的NPM INSTALL软件包时遇到此错误。
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! }
答案 0 :(得分:4)
问题在于VSCode WSL扩展程序锁定了文件并生成了错误。
解决方案是关闭VSCode上的WSL连接,或者仅关闭整个IDE并再次运行npm install命令。
答案 1 :(得分:1)
您可以通过允许不安全的权限来修复该错误
npm config set unsafe-perm=true
npm install
https://github.com/microsoft/WSL/issues/14#issuecomment-207504657
答案 2 :(得分:0)
答案 3 :(得分:0)
终于找到了通过混合多个答案来升级 npm 的方法:
# 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
PS C:\Users\CallMarl> wsl.exe -d Debian
callmarl@LAPTOP ~ % sudo npm install -g npm@latest
callmarl@LAPTOP ~ % npm -v
7.20.3
wsl.exe --set-version Debian 1