简体   繁体   English

npm - EPERM:Windows 不允许操作

[英]npm - EPERM: operation not permitted on Windows

I ran我跑了

npm config set prefix /usr/local

After running that command, When trying to run any npm commands on Windows OS I keep getting the below.运行该命令后,当尝试在 Windows 操作系统上运行任何 npm 命令时,我不断收到以下信息。

Error: EPERM: operation not permitted, mkdir 'C:\Program Files (x86)\Git\local'
at Error (native)

Have deleted all files from已删除所有文件

C:\Users\<your username>\.config\configstore\

It did not work.它不起作用。

Any suggestion?有什么建议吗?

Running this command was my mistake.运行这个命令是我的错误。

npm config set prefix /usr/local npm 配置设置前缀 /usr/local

Path /usr/local is not for windows.路径/usr/local不适用于 Windows。 This command changed the prefix variable at 'C:\\Program Files (x86)\\Git\\local'此命令更改了'C:\\Program Files (x86)\\Git\\local'的前缀变量

To access and make a change to this directory I need to run my cmd as administrator.要访问并更改此目录,我需要以管理员身份运行我的 cmd。

So I did:所以我做了:

  1. Run cmd as administrator以管理员身份运行cmd
  2. Run npm config edit (You will get notepad editor)运行npm config edit (您将获得记事本编辑器)
  3. Change prefix variable to C:\\Users\\<User Name>\\AppData\\Roaming\\npmprefix变量更改为C:\\Users\\<User Name>\\AppData\\Roaming\\npm

Then npm start works in a normal console.然后npm start在普通控制台中工作。

This is occurring because windows is not giving permission to the user to create a folder inside system drive.这是因为 Windows 没有授予用户在系统驱动器内创建文件夹的权限。 To solve this:要解决这个问题:

Right Click右键点击

The Folder > Properties > Security Tab文件夹 >属性>安全选项卡

Click on Edit to change Permissions > Select the user and give Full Control to that user.单击编辑以更改权限 > 选择用户并将完全控制权授予该用户。

有时,所需要做的就是在安装/更新软件包之前停止开发服务器。

I solved the problem by changing windows user access for the project folder:我通过更改项目文件夹的 Windows 用户访问权限解决了这个问题:

Here is a screenshot: http://prntscr.com/djdn0g这是截图: http : //prntscr.com/djdn0g

在此处输入图片说明

I recently had the same problem when I upgraded to the new version, the only solution was to do the downgraded我最近在升级到新版本时遇到了同样的问题,唯一的解决方案是降级

To uninstall:卸载:

npm uninstall npm -g

Install the previous version:安装以前的版本:

npm install npm@5.3 -g

Try update the version in another moment.稍后尝试更新版本。

重新启动 VsCode为我解决了它!

I use Windows 10. I started the CMD as administrator, and it solved the problem.我使用的是 Windows 10。我以管理员身份启动了 CMD,它解决了问题。

Find CMD, right click, and click open as administrator.找到CMD,右击,点击以管理员身份打开。

In my case, I was facing this error because my directory and its file were opened in my editor (VS code) while I was running npm install .就我而言,我遇到了这个错误,因为我的目录及其文件是在我运行npm install时在我的编辑器(VS 代码)中打开的。 I solved the issue by closing my editor and running npm install through the command line.我通过关闭编辑器并通过命令行运行npm install解决了这个问题。

I had an outdated version of npm .我有一个过时的npm版本。 I ran a series of commands to resolve this issue:我运行了一系列命令来解决这个问题:

npm cache clean --force

Then:然后:

npm install -g npm@latest --force

Then (once again):然后(再次):

npm cache clean --force

And finally was able to run this (installing Angular project) without the errors I was seeing regarding EPERM :最后能够运行这个(安装 Angular 项目)而没有我看到的关于EPERM的错误:

ng new myProject

I had the same problem, after updating npm.更新 npm 后,我遇到了同样的问题。 Solved it by re-installing latest npm again with:通过重新安装最新的 npm 解决了这个问题:

npm i -g npm

but this time with cmd running in administrating mode.但这次 cmd 在管理模式下运行。

i did all this because i suspected there was an issue with the update, mostly some missing files.我这样做是因为我怀疑更新存在问题,主要是一些丢失的文件。

I had the same problem when I tried to install the npm package AVA .当我尝试安装 npm 包AVA时遇到了同样的问题。 The solution for me was to delete the node_modules folder and force-clean the npm cache:我的解决方案是删除 node_modules 文件夹并强制清理 npm 缓存:

rm -rf node_modules
npm cache clean --force

I could then install the npm package without a problem.然后我可以毫无问题地安装 npm 包。

for me it was an issue of altering existing folders in node_module, so i nuked the whole folder and run npm install again.对我来说,这是更改 node_module 中现有文件夹的问题,所以我取消了整个文件夹并再次运行 npm install。 it works with no errors after that在那之后它没有错误

Just run cmd as admin.只需以管理员身份运行 cmd 即可。 delete old node_modules folder and run npm install again.删除旧的 node_modules 文件夹并再次运行 npm install。

Simplest way最简单的方法

Hope I am not too late for this post but recently even I too got hit by this issue.希望我写这篇文章还不算太晚,但最近我也被这个问题击中了。 And also I had no admin rights on my laptop.而且我的笔记本电脑没有管理员权限。

Here is the simplest way I fixed the bug.这是我修复错误的最简单方法。

  1. Locate the file name .npmrc (it will be in C:\\Users\\<user name>\\.npmrc )找到文件名.npmrc (它将在C:\\Users\\<user name>\\.npmrc
  2. Open it and change the path of prefix= to prefix=C:\\Users\\<user name>\\AppData\\Roaming\\npm打开并将prefix=的路径改为prefix=C:\\Users\\<user name>\\AppData\\Roaming\\npm

hope it will be helpful..希望它会有所帮助..

If you getting this error in an IDE's terminal/commands prompt, try delete node_modules, close IDE, and run the npm install command again.如果您在 IDE 的终端/命令提示符下收到此错误,请尝试删除 node_modules,关闭 IDE,然后再次运行npm install命令。 The time when IDE started but still not completed its analysis of node_modules tree is a tricky moment, when packages installation may fail because IDE still scanning node_modules contents. IDE 启动但仍未完成对 node_modules 树的分析的时间是一个棘手的时刻,因为 IDE 仍在扫描 node_modules 内容,因此软件包安装可能会失败。

This error is caused by different problems try the below one of them will work for you!此错误是由不同的问题引起的,请尝试以下其中一种对您有用!

  • try to run npm as Administrator尝试以管理员身份运行npm

  • Run cmd as administrator npm config edit (You will get notepad editor) Change Prefix variable to C:\\Users\\<User Name>\\AppData\\Roaming\\npm以管理员身份运行 cmd npm config edit (您将获得记事本编辑器)将Prefix变量更改为C:\\Users\\<User Name>\\AppData\\Roaming\\npm

  • The errors went after I disabled my anti-virus (Avast)禁用防病毒软件 (Avast) 后出现错误

  • Sometimes a simple cache clear like the below would fix it.有时像下面这样的简单缓存清除会修复它。

     npm cache clear

找到这个命令npm cache clean以快速简单的方式解决这些错误!

Happened to me since the folder/file was locked by another process.由于文件夹/文件被另一个进程锁定,因此发生在我身上。 Used a tool (LockHunter) to terminate that process and it started working again (possible reason).使用工具 (LockHunter) 终止该进程并重新开始工作(可能的原因)。

I was running create-react-app server.我正在运行 create-react-app 服务器。 Simply stopped the server and everything worked just fine.只需停止服务器,一切正常。

I had the same issue, as I was using my company LAN.我遇到了同样的问题,因为我使用的是我公司的局域网。 And I just ran cmd.exe npm and I was able to execute my other commands without any error after that.我只运行了cmd.exe npm ,之后我就可以执行我的其他命令而没有任何错误。

C:\Users\586656>cmd.exe npm
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

Just sharing this, as it may help other folks who try to do this in their office LAN.只是分享这个,因为它可能会帮助其他尝试在办公室 LAN 中执行此操作的人。 Thank you.谢谢你。

I updated my node version to 8.9.4 and ran the necessary install command again from administrator command prompt.我将节点版本更新为 8.9.4,并从管理员命令提示符再次运行必要的安装命令。 It worked for me!它对我有用!

A reboot of my laptop and then重新启动我的笔记本电脑,然后

npm install

worked for me!为我工作!

Try npm i -g npm .试试 npm i -g npm 。 NPM version 6.9 is work to me. NPM 6.9 版对我有用。

Windows 10,视窗 10,

Running the IDE (in my case IntelliJ) in administrator mode and executing npm install does resolves the problem.在管理员模式下运行 IDE(在我的情况下为 IntelliJ)并执行 npm install 确实解决了问题。

If no IDE then run CMD in administrator mode and try executing npm install如果没有 IDE 则在管理员模式下运行 CMD 并尝试执行 npm install

Try installing it globally first, using the command {npm install -g create-react-app}首先尝试全局安装它,使用命令 {npm install -g create-react-app}

And then, you can create your app using the command, {npx create-react-app }然后,您可以使用命令 {npx create-react-app } 创建您的应用程序

worked for me为我工作

Install create-react-app安装 create-react-app

I did not install create-react app.我没有安装 create-react 应用程序。 so I just run npm install -g create-react-app and the problèm was solved所以我只运行npm install -g create-react-app问题就解决了

Just stop react server and then install the package.只需stop反应服务器,然后安装包。

This issue occurs because when react is running (with yarn start or npm start ), It is using some resources.出现此问题是因为当 react 运行时(使用yarn startnpm start ),它正在使用一些资源。

Try to install npm package by running CMD as Administrator.尝试通过以管理员身份运行 CMD 来安装 npm 包。 you can headover to broad discussion on this bug at npm install throwing error EPERM .您可以在npm install throwing error EPERM上对此错误进行广泛讨论。

在 Windows Powershell 中运行 npm 命令解决了我的问题。

Same to me, My solution was close Android studio, AVD Manager, Visual Studio and reinstall.对我来说也是一样,我的解决方案是关闭 Android Studio、AVD Manager、Visual Studio 并重新安装。 I executed this command to update my expo cli:我执行了这个命令来更新我的 expo cli:

npm install -g expo-cli

Apparently anti-virus software can also cause this error.显然,防病毒软件也会导致此错误。 In my case I had Windows Security's Ransomware Protection protecting my user folders which caused this error.在我的情况下,我有 Windows 安全的勒索软件保护来保护我的用户文件夹,这导致了这个错误。

For me, It was an issue with the .npmrc file.对我来说,这是 .npmrc 文件的问题。 Which is present in C:\\Users\\myname.npmrc Somehow the content of .npmrc file got changed.存在于 C:\\Users\\myname.npmrc 不知何故,.npmrc 文件的内容发生了变化。 I have changed the content by comparing with my colleagues laptop.通过与同事的笔记本电脑进行比较,我更改了内容。 So it solved.所以它解决了。

For reference, I am adding the content of .npmrc file too作为参考,我也在添加 .npmrc 文件的内容

 ;;;;
 ;npm userconfig file
 ;this is a simple ini-formatted file
 ;lines that start with semi-colons are comments.
 ;read `npm help config` for help on the various options
 ;;;;

 //registry.npmjs.org/:_authToken=95632bcf-3056-4538-b57d-38426736e3a0
 scope=true
 @true:registry=https://registry.npmjs.org/

 ;;;;
 ;all options with default values
 ;;;;
 ;access=null

 ;allow-same-version=false

 ;always-auth=false

 ;also=null

 ;audit=true

 ;audit-level=low

 ;auth-type=legacy

 ;before=null

 ;bin-links=true

 ;browser=null

 ;ca=null

 ;cafile=undefined

 ;cache=C:\Users\myname\AppData\Roaming\npm-cache

 ;cache-lock-stale=60000

 ;cache-lock-retries=10

 ;cache-lock-wait=10000

 ;cache-max=null

 ;cache-min=10

 ;cert=null

 ;cidr=null

 ;color=true

 ;depth=null

 ;description=true

 ;dev=false

 ;dry-run=false

 ;editor=notepad.exe

 ;engine-strict=false

 ;force=false

 ;fetch-retries=2

 ;fetch-retry-factor=10

 ;fetch-retry-mintimeout=10000

 ;fetch-retry-maxtimeout=60000

 ;git=git

 ;git-tag-version=true

 ;commit-hooks=true

 ;global=false

 ;globalconfig=C:\Users\myname\AppData\Roaming\npm\etc\npmrc

 ;global-style=false

 ;group=0

 ;ham-it-up=false

 ;heading=npm

 ;if-present=false

 ;ignore-prepublish=false

 ;ignore-scripts=false

 ;init-module=C:\Users\myname\.npm-init.js

 ;init-author-name=

 ;init-author-email=

 ;init-author-url=

 ;init-version=1.0.0

 ;init-license=ISC

 ;json=false

 ;key=null

 ;legacy-bundling=false

 ;link=false

 ;local-address=undefined

 ;loglevel=notice

 ;logs-max=10

 ;long=false

 ;maxsockets=50

 ;message=%s

 ;metrics-registry=null

 ;node-options=null

 ;node-version=10.15.2

 ;offline=false

 ;onload-script=null

 ;only=null

 ;optional=true

 ;otp=null

 ;package-lock=true

 ;package-lock-only=false

 ;parseable=false

 ;prefer-offline=false

 ;prefer-online=false

 ;prefix=C:\Program Files\nodejs

 ;preid=

 ;production=false

 ;progress=true

 ;proxy=null

 ;https-proxy=null

 ;noproxy=null

 ;user-agent=npm/{npm-version} node/{node-version} {platform} {arch}

 ;read-only=false

 ;rebuild-bundle=true

 ;registry=https://registry.npmjs.org/

 ;rollback=true

 ;save=true

 ;save-bundle=false

 ;save-dev=false

 ;save-exact=false

 ;save-optional=false

 ;save-prefix=^

 ;save-prod=false

 ;scope=

 ;script-shell=null

 ;scripts-prepend-node-path=warn-only

 ;searchopts=

 ;searchexclude=null

 ;searchlimit=20

 ;searchstaleness=900

 ;send-metrics=false

 ;shell=C:\windows\system32\cmd.exe

 ;shrinkwrap=true

 ;sign-git-commit=false

 ;sign-git-tag=false

 ;sso-poll-frequency=500

 ;sso-type=oauth

 ;strict-ssl=true

 ;tag=latest

 ;tag-version-prefix=v

 ;timing=false

 ;tmp=C:\Users\myname\AppData\Local\Temp

 ;unicode=false

 ;unsafe-perm=true

 ;update-notifier=true

 ;usage=false

 ;user=0

 ;userconfig=C:\Users\myname\.npmrc

 ;umask=0

 ;version=false

 ;versions=false

 ;viewer=browser

 ;_exit=true

 ;globalignorefile=C:\Users\myname\AppData\Roaming\npm\etc\npmignore

For those trying to update config对于那些试图更新配置的人

If having trouble updating your npm config, try instead running using the -g flag .如果在更新 npm 配置时遇到问题,请尝试使用-g 标志运行。 This solved the issue on Win 10 for me after trying everything else.在尝试了其他所有方法后,这为我解决了 Win 10 上的问题。

npm config edit -g

I am able to update the config and changes are reflected everywhere.我能够更新配置并且更改会反映在任何地方。 This may be due to running npm in an organizational scope.这可能是由于在组织范围内运行 npm。

npm install cross-env 试试这个对我有用。

After trying everything and nothing works.在尝试了一切之后,没有任何效果。 Moving my working project folder to diffrent destination worked for me.将我的工作项目文件夹移动到不同的目的地对我有用。

Likely when you experience this issue, it is possible is a permission issue on your PC.当您遇到此问题时,很可能是您的 PC 上的权限问题。 Going to the PC properties and granting which ever account you use on your PC full control will solve it.转到 PC 属性并授予您在 PC 上使用的帐户完全控制权将解决它。

Again command /usr/local doesn't work on windows再次命令 /usr/local 在 Windows 上不起作用

如果清理缓存( npm cache clean --force )不能帮助您手动删除文件夹C:\\Users\\%USER_NAME%\\AppData\\Roaming\\npm-cacheand并重新安装C:\\Users\\%USER_NAME%\\AppData\\Roaming\\npm-cacheand

通过输入以下命令来解决此问题的更简单方法

npm config set cache C:\tmp\nodejs\npm-cache --global

At least I just solved my problem in this way:至少我只是用这种方式解决了我的问题:

  1. Search cmd搜索cmd
  2. Then run as administrator然后以管理员身份运行
  3. Then npm i -g expo-cli or npm config set prefix /usr/local然后npm i -g expo-clinpm config set prefix /usr/local

I just solved my problem.我刚刚解决了我的问题。

Incredibly, this happens when you are building your project, eg令人难以置信的是,当您构建项目时会发生这种情况,例如

ng build myprojet ng构建我的项目

...and you are stood up inside the dist/myprojet , maybe withing the console. ...你站在dist/myprojet里面,也许是在控制台。 So you can easily close that console window or cd .. to prevent this from happening.因此,您可以轻松关闭该控制台窗口或cd ..以防止发生这种情况。

我会使用npm-windows-upgrade更新我的 npm

The Problem I faced (In Windows Computer)我面临的问题(在 Windows 计算机中)

When I was trying to install a couple of npm packages I got the following error:当我尝试安装几个npm包时,出现以下错误:

npm - EPERM: operation not permitted - while npm was trying to rename a file npm - EPERM:不允许操作- 当npm试图重命名文件时

Here's my debug snippet for reference, if you've faced the similar problem:这是我的调试片段供您参考,如果您遇到过类似的问题:

我面临的问题

After carefully checking out the answers from other users, I have created a detailed answer for the community仔细查看了其他用户的答案,我为社区创建了一个详细的答案

My Solution for the problem我的问题解决方案

Follow the mentioned steps按照提到的步骤

  1. Right-click on the project folder右键单击项目文件夹
  2. Go to properties -> Security Tab转到properties -> Security Tab
  3. Select Users -> Edit选择Users -> Edit
  4. In the Permission for Users section, Full control -> Give a check mark in Allow -> OKPermission for Users部分, Full control -> Give a check mark in Allow -> OK
  5. Wait for Windows security to apply the new security rules等待 Windows 安全应用新的安全规则
  6. Click OK单击OK

Visualization of the steps步骤的可视化

更改安全规则

If you follow these steps and try to install npm packages again it will work properly.如果您按照这些步骤并尝试再次安装 npm 包,它将正常工作。

Note : It's a best practice to close and open up the command line again to experience the changes注意:最佳做法是再次关闭和打开命令行以体验更改

In my case, it had to do with the directory webpack was targeting to build the files.就我而言,它与 webpack 用于构建文件的目录有关。 Somehow, the directory couldn´t be deleted, even if I would try to do it manually by windows explorer.不知何故,该目录无法删除,即使我尝试通过 Windows 资源管理器手动删除。 So, you can either force delete through CMD or, as strange as it may sound, I closed my web browser that I was using to load the webpack compiled files and managed to get the directory deleted.因此,您可以通过 CMD 强制删除,或者听起来很奇怪,我关闭了用于加载 webpack 编译文件的 Web 浏览器并设法删除了目录。 Afterwards, I ran webpack again and worked.之后,我再次运行 webpack 并工作。 Maybe that was causing the directory dele block.也许那是导致目录删除块的原因。

只需重新安装 NodeJS 就为我做到了

I was having trouble with this issue as well.我也遇到了这个问题。 Try updating Node to the latest version and then try the operation again.尝试将 Node 更新到最新版本,然后重试该操作。 It may help you.它可能对你有帮助。

For me the problem come from bash terminal.对我来说,问题来自 bash 终端。 I change my terminal to powershell and it's ok.我将我的终端更改为 powershell 就可以了。

Really easy to resolve真的很容易解决

I have faced the same problem and tried all the given solutions and none of them worked.我遇到了同样的问题并尝试了所有给定的解决方案,但没有一个有效。

I got it solved after adding package.json as there was no package.json file available in the folder where I was trying to install a module and faced the same error.我在添加 package.json 后解决了这个问题,因为在我尝试安装模块的文件夹中没有可用的 package.json 文件并且遇到了同样的错误。

Give it a try maybe it helps someone试一试也许它可以帮助某人

npm init

npm init all (skip configurations)

Executing the command by specifying the version fixed it for me.通过指定版本为我修复它来执行命令。

npm install --global npm@9.2.0

Unfortunately, restarting the computer, executing npm i -g npm@latest or without @latest , exeucting npm cache clean / verify with or without respective --force argument, and even removing npm and node_modules folders and even providing access rights to the parent folder helped me.不幸的是,重新启动计算机,执行npm i -g npm@latest或不@latest ,执行npm cache clean / verify有或没有相应的--force参数,甚至删除npmnode_modules文件夹,甚至提供对父文件夹的访问权限帮助过我。

Specifying the npm version worked.指定 npm 版本有效。

My only solution for this issue was changing the directory of the project (using Window OS).我对这个问题的唯一解决方案是更改项目目录(使用 Window 操作系统)。 Initially was stored to C:/ .最初存储到C:/ when I move to C:\Users\test\Desktop started to work.当我移动到C:\Users\test\Desktop开始工作。

如果使用公司局域网,请断开与其他互联网网络的连接。

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

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