npm - EPERM:Windows上无法执行操作

212

我跑了

npm config set prefix /usr/local

运行该命令后,当我尝试在Windows操作系统上运行任何npm命令时,始终会收到以下提示。

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

已从所有文件中删除

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

它没有起作用。

有什么建议吗?


64
运行 npm cache clean --force 解决了我的问题。 - Nuhman
4
运行两次 npm cache clean --force 对我有效。 - VIshal Jain
2
你是在 cmd.exe 的“终端”(命令提示符)中运行它还是从 GitBash 终端中运行的?对我来说,当我在 GitBash 中运行它时失败了,但是当我在 cmd 中运行它时正常工作。 - Henke
1
今天我甚至在 cmd.exe 中遇到了 EPERM 错误。但是我在 C:\Program Files\nodejs 目录下运行了以下命令,似乎它起作用了:npm cache clean --force && npm install <package-name> --force --global。我还将 C:\Program Files\nodejs\node_modules 添加到了系统的 PATH 环境变量中。 - Henke
1
屏幕截图:https://i.imgur.com/VLFS7lG.png。但最好先尝试 https://dev59.com/RV0Z5IYBdhLWcg3w-ETS#44014485。 - Henke
显示剩余4条评论
49个回答

0

我需要使用npm-windows-upgrade更新我的npm。


0
在我的情况下,与webpack构建文件的目标目录有关。 不知何故,即使我尝试通过Windows资源管理器手动删除该目录,也无法将其删除。 因此,您可以通过CMD强制删除,或者,虽然听起来很奇怪,但我关闭了用于加载webpack编译文件的Web浏览器,并设法删除了该目录。 之后,我再次运行webpack并且工作正常。 也许这是导致目录删除阻塞的原因。

0

安装create-react-app

我没有安装create-react-app,所以我只需运行npm install -g create-react-app即可解决问题。


0

我曾经遇到过同样的问题,因为我在使用公司的局域网。后来我只需运行cmd.exe npm,之后就能够正常执行其他命令而不出现任何错误。

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

分享一下,希望能帮助到其他在办公室局域网中尝试这样做的人。谢谢。


0

尝试了所有的方法都没有用。 把我的工作项目文件夹移动到不同的目标位置对我有帮助。


0

通过指定版本执行命令,问题得到了解决。

npm install --global npm@9.2.0

不幸的是,重启计算机、执行npm i -g npm@latest或不带@latest,执行npm cache clean/verify,带或不带相应的--force参数,甚至删除npmnode_modules文件夹,甚至为父文件夹提供访问权限都没有帮助我。

指定npm版本可以解决问题。


0

我曾经遇到过同样的问题,尝试了所有给出的解决方案,但都没有起作用。

后来我在添加 package.json 后解决了这个问题,因为在我尝试安装模块并遇到相同错误的文件夹中没有可用的 package.json 文件。

也许你可以试一试,它可能会帮助到其他人。

npm init

npm init all (skip configurations)

0
对我来说,这是一个与 .npmrc 文件有关的问题。该文件位于 C:\Users\myname.npmrc 中。 不知何故,.npmrc 文件的内容发生了变化。我通过与同事的笔记本电脑进行比较,已经更改了其内容。所以问题得到了解决。
为了参考,我也添加了 .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

-7
如果使用公司局域网,请断开连接并尝试其他互联网网络。

1
请先仔细阅读问题并理解问题所在,然后尝试以描述性和相关的格式回答如何以及为什么你的答案可能是一个可行的解决方案。希望能帮到你! - Fahim Uddin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接