npm WARN saveError EPERM:不允许操作,重命名 'C:\...\package.json.3542172463' -> 'C:\...\package.json'
npm WARN saveError EPERM: operation not permitted, rename 'C:\...\package.json.3542172463' -> 'C:\...\package.json'
环境:
Node: 8.11.2 (installed from nvm)
npm: 5.6.0
OS: Windows Server 2016
AV: Only Windows Defender but it has been disabled
使用的命令:
npm install
npm install grunt
当我 运行 第一个命令 (npm install) 时 package.json 文件中描述的所有模块都已正确安装。
当我 运行 第二个命令 (npm install g运行t) 我得到一个错误:
npm WARN saveError EPERM: operation not permitted, rename 'C:\...\package.json.3542172463' -> 'C:\...\package.json'
removed 762 packages in 16.89s
并从我的 node_module 目录中删除了数百个模块。
有人知道是什么导致了这样的问题吗?
我已经尝试禁用代理,清除 npm 缓存,禁用 AV(只有 Windows Defender)没有结果。
更新到最新的 npm 版本 (v6.2.0) 成功了:)
因为我在 Windows 上使用 nvm 安装 Node.js 我在更新 npm 时遇到了一些问题,但我找到了下面的脚本,由 Adrien Pyke 编写(基于@arfaWong 的想法) 并发表于:
https://github.com/coreybutler/nvm-windows/issues/300#issuecomment-390293097
@echo off
SETLOCAL EnableDelayedExpansion
if [%1] == [] (
echo Pass in the version you would like to install, or "latest" to install the latest npm version.
) else (
set wanted_version=%1
if "!wanted_version!" == "latest" (
for /f %%i in ('npm show npm version') do set wanted_version=%%i
)
for /f %%i in ('npm -g -v') do set cur_version=%%i
if "!cur_version!" == "!wanted_version!" (
echo Already on npm version !wanted_version!.
) else (
echo Updating to !wanted_version!...
set node_path=!PROGRAMFILES!\nodejs
rename "!node_path!\npm" npm2
rename "!node_path!\npm.cmd" npm2.cmd
rename "!node_path!\node_modules\npm" npm2
node "!node_path!\node_modules\npm2\bin\npm-cli.js" i npm@!wanted_version! -g
for /f %%i in ('npm -g -v') do set new_version=%%i
echo New version installed is !new_version!
if "!new_version!" == "!wanted_version!" (
echo Successfully updated to !wanted_version!. Cleaning up backups...
del "!node_path!\npm2"
del "!node_path!\npm2.cmd"
@RD /S /Q "!node_path!\node_modules\npm2"
echo Update complete.
) else (
echo Something went wrong. Rolling back.
if exist "!node_path!\npm" (
del "!node_path!\npm"
)
if exist "!node_path!\npm.cmd" (
del "!node_path!\npm.cmd"
)
if exist "!node_path!\node_modules\npm" (
@RD /S /Q "!node_path!\node_modules\npm"
)
rename "!node_path!\npm2" npm
rename "!node_path!\npm2.cmd" npm.cmd
rename "!node_path!\node_modules\npm2" npm
)
)
)
环境:
Node: 8.11.2 (installed from nvm)
npm: 5.6.0
OS: Windows Server 2016
AV: Only Windows Defender but it has been disabled
使用的命令:
npm install
npm install grunt
当我 运行 第一个命令 (npm install) 时 package.json 文件中描述的所有模块都已正确安装。
当我 运行 第二个命令 (npm install g运行t) 我得到一个错误:
npm WARN saveError EPERM: operation not permitted, rename 'C:\...\package.json.3542172463' -> 'C:\...\package.json'
removed 762 packages in 16.89s
并从我的 node_module 目录中删除了数百个模块。
有人知道是什么导致了这样的问题吗?
我已经尝试禁用代理,清除 npm 缓存,禁用 AV(只有 Windows Defender)没有结果。
更新到最新的 npm 版本 (v6.2.0) 成功了:)
因为我在 Windows 上使用 nvm 安装 Node.js 我在更新 npm 时遇到了一些问题,但我找到了下面的脚本,由 Adrien Pyke 编写(基于@arfaWong 的想法) 并发表于: https://github.com/coreybutler/nvm-windows/issues/300#issuecomment-390293097
@echo off
SETLOCAL EnableDelayedExpansion
if [%1] == [] (
echo Pass in the version you would like to install, or "latest" to install the latest npm version.
) else (
set wanted_version=%1
if "!wanted_version!" == "latest" (
for /f %%i in ('npm show npm version') do set wanted_version=%%i
)
for /f %%i in ('npm -g -v') do set cur_version=%%i
if "!cur_version!" == "!wanted_version!" (
echo Already on npm version !wanted_version!.
) else (
echo Updating to !wanted_version!...
set node_path=!PROGRAMFILES!\nodejs
rename "!node_path!\npm" npm2
rename "!node_path!\npm.cmd" npm2.cmd
rename "!node_path!\node_modules\npm" npm2
node "!node_path!\node_modules\npm2\bin\npm-cli.js" i npm@!wanted_version! -g
for /f %%i in ('npm -g -v') do set new_version=%%i
echo New version installed is !new_version!
if "!new_version!" == "!wanted_version!" (
echo Successfully updated to !wanted_version!. Cleaning up backups...
del "!node_path!\npm2"
del "!node_path!\npm2.cmd"
@RD /S /Q "!node_path!\node_modules\npm2"
echo Update complete.
) else (
echo Something went wrong. Rolling back.
if exist "!node_path!\npm" (
del "!node_path!\npm"
)
if exist "!node_path!\npm.cmd" (
del "!node_path!\npm.cmd"
)
if exist "!node_path!\node_modules\npm" (
@RD /S /Q "!node_path!\node_modules\npm"
)
rename "!node_path!\npm2" npm
rename "!node_path!\npm2.cmd" npm.cmd
rename "!node_path!\node_modules\npm2" npm
)
)
)