简体   繁体   English

npm ERR:错误:EPERM,不允许操作,重命名

[英]npm ERR! Error: EPERM: operation not permitted, rename

When I execute npm install I get this error当我执行npm install时出现此错误

npm ERR: Error: EPERM, operation not permitted: rename C:\projects******\node_modules\react-async-script' -> 'C.\projects*******\node_modules.react-async-script.DELETE' npm ERR:错误:EPERM,不允许操作:重命名 C:\projects******\node_modules\react-async-script' -> 'C.\projects******\node_modules.react-异步脚本.DELETE'

  • I am running the cmd as administrator我以管理员身份运行 cmd
  • I ran npm cache clean before我之前跑过npm cache clean
  • I made sure all the other applications don't have anything related to node_modules open我确保所有其他应用程序都没有与node_modules open 相关的任何内容

In my situation this helped:在我的情况下,这有帮助:

Before proceeding to execute these commands close all VS Code instances.在继续执行这些命令之前,请关闭所有 VS Code 实例。

  1. clean cache with清理缓存

     npm cache clean --force
  2. install the latest version of npm globally as admin:以管理员身份全局安装最新版本的 npm:

     npm install -g npm@latest --force
  3. clean cache with清理缓存

     npm cache clean --force
  4. Try to install your component once again.再次尝试安装您的组件。

I hope this fix your issue.我希望这能解决您的问题。 If not, you may temporarily disable your antivirus program and try again.如果没有,您可以暂时禁用防病毒程序并重试。

I got it working when tried npm install with a force option to fetch remote resources even if a local copy exists on disk.尝试使用强制选项 npm install 获取远程资源时,即使磁盘上存在本地副本,我也能正常工作。 Try running尝试跑步

npm install --force

Updated For some of my colleagues this solution was not working.更新对于我的一些同事,此解决方案不起作用。 But we tried using yarn instead of npm.但是我们尝试使用yarn而不是npm。 It works (faster as well) without any issues all the time它始终有效(也更快)而没有任何问题

yarn install [package-name]

Not package.json , but for whatever reason, my node_modules/ had become read-only.不是package.json ,但无论出于何种原因,我的node_modules/已成为只读。 Resetting that fixed this.重置解决了这个问题。

For me i just closed the Code editor (VS Code) and then run the same command.对我来说,我只是关闭了代码编辑器(VS Code),然后运行相同的命令。 And that solves the issue for me.这为我解决了这个问题。

If you want to avoid the --force option (which is always a better approach) , I suggest making sure that you have stopped running the project, as this is usually the main reason for locking the files in almost 90% of the cases I have seen如果您想避免使用--force选项(这总是更好的方法)我建议确保您已停止运行项目,因为这通常是我在几乎 90% 的情况下锁定文件的主要原因见过

I suggest the following steps in this order:我建议按此顺序执行以下步骤:

1- In Angular stopping ng s and in React stopping npm start usually solves this issue because usually this error happens if a development server is running the project as it locks some files & then npm can't update them thus throwing this error 1- 在 Angular 中,停止ng s和在 React 中停止npm start通常可以解决这个问题,因为如果开发服务器正在运行项目,因为它锁定了一些文件,然后 npm 无法更新它们,因此通常会发生此错误,从而引发此错误

2- If the above doesn't work, then try closing the code editor that has the workspace opened in it (maybe it was locking some files or something) 2-如果上述方法不起作用,请尝试关闭其中打开了工作区的代码编辑器(可能是锁定了某些文件或其他内容)

So try closing the code editor & running:所以尝试关闭代码编辑器并运行:

npm install

3- If still it doesn't work, then maybe you can try the --force option 3-如果仍然不起作用,那么也许您可以尝试--force选项

npm install --force

I was getting that same error and according to https://github.com/Medium/phantomjs/issues/19 it could be caused by your antivirus software.我遇到了同样的错误,根据https://github.com/Medium/phantomjs/issues/19,这可能是由您的防病毒软件引起的。 I disabled mine for the duration of the install and executed "npm install" on cmd as admin and it worked.我在安装期间禁用了我的,并以管理员身份在 cmd 上执行了“npm install”并且它工作正常。 Hope this helps.希望这会有所帮助。

As Martin Kearn pointed out in a comment, closing Visual Studio resolved these npm permission issues for me.正如 Martin Kearn 在评论中指出的那样,关闭 Visual Studio为我解决了这些 npm 权限问题。 Evidently VS sometimes locks files in node_modules .显然 VS 有时会锁定node_modules文件。

I was getting the same thing.我得到了同样的东西。 I didn't find this anywhere but it hit me that our VMs tend to change files to a read-only state.我在任何地方都没有找到这个,但我发现我们的虚拟机倾向于将文件更改为只读状态。 So I opened package.json 's file properties and deselected Read-only in the "General" tab.所以我打开package.json的文件属性并在“常规”选项卡中取消选择Read-only

Steps步骤

  1. Go to the package.json file.转到package.json文件。
  2. Right-click and select Properties .右键单击并选择属性
  3. In the General tab, Attributes section, deselect Read-only .General选项卡的Attributes部分中,取消选择Read-only
  4. Click Apply to apply the change.单击应用以应用更改。

This is a typical error caused by Antivirus.这是由 Antivirus 引起的典型错误。 There is a workaround for cases like mine, where I can't disable A/V (Company Policy).对于像我这样无法禁用 A/V(公司政策)的情况,有一种解决方法。

You have to change the polyfills.js inside Npm package:你必须改变polyfills.jsNpm包:

[NODE_HOME]/node_modules/npm/node_modules/graceful_fs/polyfills.js

Look for this statement:查找此语句:

if (process.platform === "win32") {

Inside of this statement, there is a timeout making a retry in case of error.在这个语句中,有一个超时会在出现错误时重试。 The problem is that in some cases, after the timeout, the file is still locked by the A/V.问题是在某些情况下,超时后文件仍被 A/V 锁定。 The solution is rip out the timeout and let this statement in loop.解决方案是删除超时并让此语句循环。 The change with the previous code commented:与先前代码的更改注释:

if (platform === "win32") {

fs.rename = (function (fs$rename) { return function (from, to, cb) {
  var start = Date.now()
  var backoff = 0;
  fs$rename(from, to, function CB (er) {
    if (er
        && (er.code === "EACCES" || er.code === "EPERM")
        /*&& Date.now() - start < 60000*/) {
            console.log("Retrying rename file: " + from + " <> " + to)
            fs$rename(from, to, CB);
      /*setTimeout(function() {
        fs.stat(to, function (stater, st) {
          if (stater && stater.code === "ENOENT")
            fs$rename(from, to, CB);
          else
            cb(er)
        })
      }, backoff)*/
      if (backoff < 100)
        backoff += 10;
      return;
    }
    if (cb) cb(er)
  })
}})(fs.rename)
}

I have had this issue multiple times only in Windows I try these in the order usually.我仅在 Windows 中多次遇到此问题,我通常按顺序尝试这些问题。

  1. npm install --force
  2. Check if node_modules is set to read-only and remove if it is检查 node_modules 是否设置为只读,如果是则删除
  3. Delete node_modules/删除node_modules/
  4. Check if any editor is opened that could have access to the root folder of the project检查是否打开了任何可以访问项目根文件夹的编辑器
  5. Reboot :(重新启动:(

Usually trying npm install after one of those steps will resolve it.通常在这些步骤之一之后尝试npm install将解决它。

就我而言,某些东西被锁定,快速重启解决了它。

尝试将文件重命名为另一个已经存在的文件名可能会导致 Windows 上的EPERM错误。

关闭 PHPStorm 为我解决了这个问题。

只需关闭 VS Code 即可为我解决问题

I had the same problem after updating to npm to 5.4.2, npm start giving the same error for most npm commands.将 npm 更新到 5.4.2 后,我遇到了同样的问题,npm 开始对大多数 npm 命令给出相同的错误。 Some solution suggest to run it with --no-optional , but it didn't always work.一些解决方案建议使用--no-optional运行它,但它并不总是有效。

Others suggested to downgrade, but I didn't want to downgrade.其他人建议降级,但我不想降级。

I suspected that there was a problem with the installation, not sure what it was.我怀疑是安装有问题,不知道是什么问题。

So I re-updated my npm:所以我重新更新了我的 npm:

npm i -g npm

and worked fine since then.从那以后工作得很好。

I did the following:我做了以下事情:

  1. Upgraded the npm to the latest version: npm install -g npm@6.5.0-next.0将 npm 升级到最新版本: npm install -g npm@6.5.0-next.0
  2. deleted the npm-cache folder from: c:/users/[username]/AppData/Roaming/npm-cache从以下位置删除 npm-cache 文件夹: c:/users/[username]/AppData/Roaming/npm-cache
  3. Did cache clean : npm cache clean --force缓存是否干净: npm cache clean --force
  4. Ran the npm install . npm install

I remounted my window disks with the metadata flag, and instantly helped: https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/我用元数据标志重新安装了我的窗口磁盘,并立即提供了帮助: https : //devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/

after that no need anymore to use sudo for npm commands as the metadata keeps windows and linux file/directory permissions in check.之后不再需要对 npm 命令使用 sudo,因为元数据会检查 Windows 和 linux 文件/目录权限。

npm was failing for me at scandir for: npm 在scandir对我来说失败了:

npm install -g webpack

...which might be caused by npm attempting to "modify" files that were potentially locked by other processes as mentioned here and in few other github threads. ...这可能是由 npm 尝试“修改”可能被其他进程锁定的文件引起的,如此和其他几个 github 线程中提到。 After force cleaning the cache, verifying cache, running as admin, disabling the AV, etc the solution that actually worked for me was closing any thing that might be placing a lock the files (ie restarting my computer).在强制清理缓存、验证缓存、以管理员身份运行、禁用 AV 等之后,实际对我有用的解决方案是关闭任何可能锁定文件的东西(即重新启动我的计算机)。

I hope this helps someone struggling.我希望这可以帮助正在挣扎的人。

I had the same problem.我有同样的问题。 The reason for the error is unsupported characters in the path to the file.错误的原因是文件路径中的字符不受支持。 Replaced the cyrillic in English - it helped.用英语替换了西里尔字母 - 它有帮助。

For some, AppRoot\\npm folder could be an issue.对于某些人来说, AppRoot\\npm 文件夹可能是一个问题。 Sometimes the AppRoot folder is marked as network shared and thus Antivirus blocks the stuff.有时 AppRoot 文件夹被标记为网络共享,因此防病毒软件会阻止这些内容。 Follow below link for complete solution.请按照以下链接获取完整的解决方案。

https://alastaircrabtree.com/fixing-intermittant-eperm-operation-not-permitted-on-npm-install/ https://alastaircrabtree.com/fixing-intermittant-eperm-operation-not-permitted-on-npm-install/

I hope this helps.我希望这会有所帮助。

Open the command prompt as administrator and navigate to the project location and then run npm install.以管理员身份打开命令提示符并导航到项目位置,然后运行 ​​npm install。 it worked for me.它对我有用。

In my case running npm: v6.9.0 && node: v10.16.1 on Windows , I had to run my CLI (git bash) as administrator .在我的情况下,在Windows上运行npm: v6.9.0 && node: v10.16.1 ,我必须以管理员身份运行我的 CLI (git bash)。 Then packages were installed without any warnings/errors然后安装软件包没有任何警告/错误

If you are having the issue on PHP Storm:如果您在 PHP Storm 上遇到问题:

  1. Close terminal tab关闭终端选项卡
  2. Open a new terminal tab打开一个新的终端选项卡

我在 VSCode 中使用终端,我意识到我使用的是bash终端而不是node终端。

以管理员身份运行 CLI 总是为我解决问题

I am using macOS catalina ,我正在使用 macOS catalina ,

      npm init 

I got error我有错误

       operation not permitted, uv_cwd

in 2021, this is how you can fix this problem.在 2021 年,这就是您解决此问题的方法。

very simple:很简单:

step 1: go to parent folder第 1 步:转到父文件夹

         cd ../
         

step 2: go to your project folder again,第 2 步:再次转到您的项目文件夹,

         cd  your-project-folder

That is it.就是这样。 it works.它有效。

My answer is to do npm cache clean --force first.我的答案是先做npm cache clean --force Then run npm install -g npm@5.3.0 to install npm 5.3.0 version.然后运行npm install -g npm@5.3.0安装 npm 5.3.0 版本。 for me, this npm version works with no trouble.对我来说,这个 npm 版本没有问题。

Just delete the package folder from the path of npm global packages.只需从 npm 全局包的路径中删除包文件夹即可。 then reinstall the package.然后重新安装包。 Note that the packages are globally installed in: C:\\Users\\your-name\\AppData\\Roaming\\npm\\node_modules请注意,软件包全局安装在: C:\\Users\\your-name\\AppData\\Roaming\\npm\\node_modules

I was having the same problem in windows 10. Just follows these steps :我在 Windows 10 中遇到了同样的问题。只需按照以下步骤操作:

  • Open cmd as administrator.以管理员身份打开cmd。

  • install uppdated npm package.安装更新的 npm 包。

  • npm i -g npm npm i -g npm

  • npm init --yes npm init --yes

Running commands as Super Admin worked for me.以超级管理员身份运行命令对我有用。 Retry after closing Editor your are working in.关闭您正在使用的编辑器后重试。

When I execute npm install I get this error当我执行npm install此错误

npm ERR! npm ERR! Error: EPERM: operation not permitted, rename C:\\projects******\\node_modules\\react-async-script' -> 'C:\\projects*******\\node_modules.react-async-script.DELETE'错误:EPERM:不允许操作,请重命名C:\\ projects ****** \\ node_modules \\ react-async-script'->'C:\\ projects ******* \\ node_modules.react-async-script 。删除'

  • I am running the cmd as administrator我以管理员身份运行cmd
  • I ran npm cache clean before我之前运行过npm cache clean
  • I made sure all the other applications don't have anything related to node_modules open我确保所有其他应用程序都没有打开任何与node_modules相关的node_modules

When I execute npm install I get this error当我执行npm install此错误

npm ERR! npm ERR! Error: EPERM: operation not permitted, rename C:\\projects******\\node_modules\\react-async-script' -> 'C:\\projects*******\\node_modules.react-async-script.DELETE'错误:EPERM:不允许操作,请重命名C:\\ projects ****** \\ node_modules \\ react-async-script'->'C:\\ projects ******* \\ node_modules.react-async-script 。删除'

  • I am running the cmd as administrator我以管理员身份运行cmd
  • I ran npm cache clean before我之前运行过npm cache clean
  • I made sure all the other applications don't have anything related to node_modules open我确保所有其他应用程序都没有打开任何与node_modules相关的node_modules

When I execute npm install I get this error当我执行npm install此错误

npm ERR! npm ERR! Error: EPERM: operation not permitted, rename C:\\projects******\\node_modules\\react-async-script' -> 'C:\\projects*******\\node_modules.react-async-script.DELETE'错误:EPERM:不允许操作,请重命名C:\\ projects ****** \\ node_modules \\ react-async-script'->'C:\\ projects ******* \\ node_modules.react-async-script 。删除'

  • I am running the cmd as administrator我以管理员身份运行cmd
  • I ran npm cache clean before我之前运行过npm cache clean
  • I made sure all the other applications don't have anything related to node_modules open我确保所有其他应用程序都没有打开任何与node_modules相关的node_modules

I closed VS, deleted the node_modules folder.我关闭了 VS,删除了 node_modules 文件夹。

Then ran:然后跑:

npm i -D -E clean-webpack-plugin@3.0.0 css- 
loader@3.4.2 html-webpack-plugin@3.2.0 mini-css- 
extract-plugin@0.9.0 ts-loader@6.2.1 typescript@3.7.5 
webpack@4.41.5 webpack-cli@3.3.10 

Then had to change the property to not read only on node_modules folder once it got done running.然后必须将属性更改为在 node_modules 文件夹完成运行后不只读。

Then ran:然后跑:

npm i @microsoft/signalr @types/node

Then opened back up the project in VS and the package.json looked right with the dependencies.然后在 VS 中打开备份项目,package.json 看起来与依赖项正确。

Along the same lines as others talking about read only on node_modules folder and closing down VS to run npm install over.与其他人谈论在 node_modules 文件夹上只读并关闭 VS 以运行 npm install 相同。

After a lot of try I resolved this with following steps:经过多次尝试,我通过以下步骤解决了这个问题:

 0. Run `cmd` or `powershell` as admin
  1. clean cachec npm clean cache --force clean cachec npm clean cache --force
  2. delete insides of %AppData%/npm-cache/删除 %AppData%/npm-cache/ 的内部
  3. delete %temp%删除 %temp%
  4. Delete the npm module which is causing the error.删除导致错误的 npm 模块。 For me it was iconv .对我来说是iconv So deleted iconv and iconv-lite所以删除了iconviconv-lite
  5. When I built again, I got failure reason as a virus inside app-builder .当我再次构建时,我的失败原因是app-builder的病毒。 I ran windows defender on node-module and removed that virus.我在节点模块上运行 Windows Defender 并删除了该病毒。 Then, build again.然后,再次构建。
  6. This time I was successful.这次我成功了。

These steps solved for me这些步骤为我解决了

Go to the package.json file in the file explorer Right click & select Properties.转到文件资源管理器中的 package.json 文件右键单击并选择“属性”。 Deselect Read-only.取消选择只读。 Click Apply点击应用

NOTE: (In case if it is already deselected , check and uncheck the read-only once and click Apply)注意:(如果它已经被取消选中,请选中并取消选中只读一次,然后单击“应用”)

Most likely the node_modules folder became Read Only .很可能node_modules文件夹变成了Read Only You can try updating folder permissions but if you do not have admin access, the npm install --force will work.您可以尝试更新文件夹权限,但如果您没有管理员访问权限, npm install --force将起作用。

I'm using iTerm.我正在使用 iTerm。 After restarting iTerm, the error was gone.重新启动 iTerm 后,错误消失了。

就我而言,我只是使用 cmd 以管理员身份运行 npm install

I was facing the same issue, Used npm cache clear command in cmd with open as Adminitrator .我遇到了同样的问题,在cmd使用了npm cache clear命令,并且open as Adminitrator Close VScode and reopened it.关闭 VScode 并重新打开它。 and it worked.它奏效了。

In my case, I had a Windows Explorer opened to the node_modules directory causing issue.就我而言,我在 node_modules 目录中打开了一个 Windows 资源管理器,导致了问题。 Closing this did the trick.关闭它就成功了。

In my case it was the fact that I actually moved the project to Trash, re-cloned the project from git, but seems like Terminal was still pointing to the folder moved in Trash.就我而言,事实是我实际上将项目移到了垃圾箱,从 git 重新克隆了项目,但终端似乎仍然指向在垃圾箱中移动的文件夹。 I only had to cd back to newly cloned project, and everything worked just fine.我只需要cd回到新克隆的项目,一切都很好。

In my case I was doing a fs.renameSync when this error happened.就我而言,发生此错误时,我正在执行fs.renameSync

It seems that the "new" path already exists and deleting it doesn't throw an error.似乎“新”路径已经存在,删除它不会引发错误。

It doesn't really fix the issue but if you just wanna build the app just like I do, then this works.它并没有真正解决问题,但如果您只是想像我一样构建应用程序,那么这可行。

  1. I reinstall NodeJSreinstall NodeJS
  2. Closed VSCode
  3. Open VSCode to where the project was to get it to run without issues Open VSCode to where the project让它毫无问题地运行

I came here with the same error, followed all the answers here, and none solved it.我带着同样的错误来到这里,按照这里的所有答案,都没有解决它。 I started going through my package.json removing all suspicious packages.我开始通过我的 package.json 删除所有可疑的包。 Removing this unnecessary one solved our problem.删除这个不必要的解决了我们的问题。 "npm": "^8.3.2"<\/code>

"

I think it should be related to updating npm issue.我认为这应该与更新 npm 问题有关。 As a workaround for now you can specify npm version as 8.3.1.作为现在的解决方法,您可以将 npm 版本指定为 8.3.1。

  - name: Install latest npm version
    run: npm install --global npm@8.3.1

July 2022, I'm updating Angular 13 to 14 and I faced this issue. 2022 年 7 月,我将Angular 13 更新到 14 ,我遇到了这个问题。 None of the above solutions worked so I just restarted the laptop and the npm i --force worked It seems like one process on the background is locking the access to certain node_modules files (you may have an ng serve running somewhere, or been launched by a git bash which you close but kept running on the background)上述解决方案均无效,因此我只是重新启动了笔记本电脑npm i --force worked似乎后台的一个进程正在锁定对某些 node_modules 文件的访问(您可能在某处运行 ng serve 或由一个 git bash 您关闭但继续在后台运行)

This simple remady works for me这个简单的修复对我有用

  • Open PowerShell with un as administrator以管理员身份用un打开PowerShell

在此处输入图像描述

  • Run this command运行这个命令

    npm i

I face this issue multiple times. 我多次面对这个问题。 It turns out, that it has nothing to do with permissions, cache, etc. The error message is misleading. 事实证明,它与权限,缓存等无关。错误消息具有误导性。 For node v 6.x you will see more detailed error stack but not after 7.x For me and my colleges, the issue is timeout function. 对于节点v 6.x,您将看到更详细的错误堆栈,但不会在7.x之后看到我和我的大学,问题是超时功能。 Basically the package install has not finished yet (ie holding the directory) when npm tries to delete it. 当npm尝试删除它时,基本上包安装尚未完成(即保存目录)。 in node 6.x you can see that in finalize.js now it's gone! 在节点6.x中你可以看到在finalize.js中它已经消失了! Just use yarn. 只需使用纱线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM