npm - EPERM:Windows上不允许操作

时间:2016-01-04 22:21:25

标签: javascript node.js npm bower npm-install

我跑了

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\

它不起作用。

有什么建议吗?

41 个答案:

答案 0 :(得分:62)

运行此命令是我的错误。

  

npm config set prefix / usr / local

路径/usr/local不适用于Windows。此命令更改了'C:\Program Files (x86)\Git\local'

处的前缀变量

要访问此目录并对其进行更改,我需要以管理员身份运行我的cmd。

所以我做了:

  1. 以管理员身份运行cmd
  2. 运行npm config edit(您将获得记事本编辑器)
  3. prefix变量更改为C:\Users\<User Name>\AppData\Roaming\npm
  4. 然后npm start在普通控制台中运行。

答案 1 :(得分:23)

我通过更改旧版本的Windows用户访问权限来解决问题:

以下是截图: http://prntscr.com/djdn0g

enter image description here

答案 2 :(得分:21)

我最近遇到了同样的问题,当我升级到新版本时,唯一的解决方案是降级

要卸载:

npm uninstall npm -g

安装以前的版本:

npm install npm@5.3 -g

尝试在另一个时刻更新版本。

答案 3 :(得分:19)

这是因为Windows未授予用户在系统驱动器内创建文件夹的权限。要解决这个问题:

右键单击

文件夹&gt; 属性&gt; 安全标签

点击修改以更改权限&gt;选择用户并为该用户提供完全控制

答案 4 :(得分:14)

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

答案 5 :(得分:6)

更新npm后我遇到了同样的问题。通过以下方式重新安装最新的npm解决了这个问题:

npm i -g npm

但这次cmd在管理模式下运行。

我做了所有这些因为我怀疑更新存在问题,主要是一些丢失的文件。

答案 6 :(得分:5)

对我来说这是一个改变node_module中现有文件夹的问题,所以我修改了整个文件夹并再次运行npm install。

后,它没有任何错误

答案 7 :(得分:5)

我使用的是Windows 10。 我以管理员身份启动了CMD,它解决了这个问题。

找到CMD,右键单击,然后单击“以管理员身份打开”。

答案 8 :(得分:5)

我有一个过时的import React from 'react' import SuperAgent from 'superagent' import { string } from 'prop-types' class ContactForm extends React.Component { constructor(props) { super(props) this.handleClick = this.handleClick.bind(this) this.onChange = this.onChange.bind(this) this.submitForm = this.submitForm.bind(this) this.state = { data: {} } } handleClick (e) { e.preventDefault() this.submitForm() } onChange (e) { this.setState(...this.state.data, {[e.target.name]: e.target.value }) } submitForm () { const { data } = this.state SuperAgent .post('https://something.com') .set('Content-Type', 'application/json') .send({ data: { 'name': 'name', 'formName': 'form', 'emailName': 'email', data }}) .end((err, res) => { if (err || !res || !res.body) return console.log(err) window.location='/contact-form-successful.html' }) } render () { return ( <section className='contact-form' id={this.props.id}> <form id='contact-form' method='post' action='#' onSubmit={this.handleClick}> <input name="username" type="text" value='' onChange={this.onChange} /> <input name="email" type="email" value='' onChange={this.onChange} /> <input name="birthdate" type="text" value='' onChange={this.onChange} /> <button>Send data!</button> </form> </section> ) } } export default ContactForm ContactForm.propTypes = { id: string } ContactForm.defaultProps = { id: 'contact-form' } 版本。我运行了一系列命令来解决此问题:

npm

然后:

npm cache clean --force

然后(再次):

npm install -g npm@latest --force

最后,我能够运行此程序(安装Angular项目),而没有遇到关于npm cache clean --force 的错误:

EPERM

答案 9 :(得分:5)

对于我来说,我遇到此错误是因为在运行npm install时,我的目录及其文件是在编辑器中打开的(VS代码)。我通过关闭编辑器并通过命令行运行npm install解决了该问题。

答案 10 :(得分:3)

此错误是由不同的问题引起的,请尝试以下一种方法为您服务!

  • 尝试以管理员身份运行npm

  • 以管理员npm config edit身份运行cmd(您将获得记事本编辑器) 将Prefix变量更改为C:\Users\<User Name>\AppData\Roaming\npm

  • 我禁用防病毒软件(Avast)后出现错误

  • 有时候,像下面这样的简单缓存清除将解决此问题。

     npm cache clear
    

答案 11 :(得分:3)

当我尝试安装npm软件包AVA时遇到了同样的问题。对我来说,解决方案是删除node_modules文件夹并强制清理npm缓存:

rm -rf node_modules
npm cache clean --force

然后我可以毫无问题地安装npm软件包。

答案 12 :(得分:1)

最简单的方法

希望这篇文章对我来说还不算太晚,但是最近我也被这个问题所困扰。而且我的笔记本电脑也没有管理员权限。

这是我修复错误的最简单方法。

  1. 找到文件名.npmrc(将在C:\Users\<user name>\.npmrc中)
  2. 打开它,并将prefix=的路径更改为prefix=C:\Users\<user name>\AppData\Roaming\npm

希望这会有所帮助。

答案 13 :(得分:1)

我正在运行create-react-app服务器。只是停止了服务器,一切正常。

答案 14 :(得分:1)

重新启动VsCode 为我解决了

答案 15 :(得分:1)

如果在IDE的终端/命令提示符下出现此错误,请尝试删除node_modules,关闭IDE,然后再次运行npm install命令。 IDE启动但仍未完成对node_modules树的分析的时间是一个棘手的时刻,由于IDE仍在扫描node_modules的内容,因此软件包安装可能失败。

答案 16 :(得分:1)

我遇到了同样的问题,因为我正在使用我公司的局域网。我刚刚运行cmd.exe npm,之后我能够执行其他命令而没有任何错误。

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

分享这个,因为它可能会帮助其他尝试在办公室局域网中执行此操作的人。谢谢。

答案 17 :(得分:1)

因为文件夹/文件被另一个进程锁定而发生。使用工具(LockHunter)终止了该过程,然后再次开始工作(可能是原因)。

答案 18 :(得分:1)

只需以管理员身份运行cmd。删除旧的node_modules文件夹并再次运行npm install。

答案 19 :(得分:0)

针对那些尝试更新配置的人

如果无法更新npm配置,请尝试使用 -g标志运行。在尝试了所有其他方法之后,这为我解决了Win 10上的问题。

npm config edit -g

我能够更新配置,更改无处不在。这可能是由于在组织范围内运行npm。

答案 20 :(得分:0)

我会使用 deque

更新我的 npm

答案 21 :(得分:0)

令人难以置信的是,当您构建项目时会发生这种情况,例如

<块引用>

ng build myprojet

...然后你站在 dist/myprojet 里面,也许是在控制台。因此,您可以轻松关闭该控制台窗口或 cd .. 以防止发生这种情况。

答案 22 :(得分:0)

安装 create-react-app

我没有安装 create-react 应用程序。所以我只运行npm install -g create-react-app,问题就解决了

答案 23 :(得分:0)

先尝试全局安装,使用命令 {npm install -g create-react-app}

然后,您可以使用以下命令创建您的应用程序, {npx create-react-app }

为我工作

答案 24 :(得分:0)

至少我是这样解决了我的问题:

  1. 搜索const { MessageEmbed } = require('discord.js') module.exports = { name : 'poll', category : 'util', cooldown: 5, description : 'Makes a poll', permissions: ["MANAGE_MESSAGES"], run : async(client, message, args) => { let num = { 1: '1️⃣', 2: '2️⃣', 3: '3️⃣', 4: '4️⃣', 5: '5️⃣', 6: '6️⃣', 7: '7️⃣', 8: '8️⃣', 9: '9️⃣', 10: '?' } var questionRe = /"(.*)"/gmi let question = args.join(" ").match(questionRe) if (!questionRe) return message.args("You did not provide question") let options = args.join(" ").slice(question[0].length).split(" | ") let result = "" if (options.length <= 1) { result += "✅ : Yes\n" result += "❌ : No" return message.send(`? ${question}`, `React with one of the following to determine your choice!\n${result}`, "BLUE").then(async msg => { await msg.react("✅") await msg.react("❌") }) } else { if (options.length > 9) return message.error("Cannot be more than 9 options") result = options.map((c, i) => { return `${num[i + 1]}: ${c}` }) let msg = await message.sendE(`? ${question}`, `React with one of the following to determine your choice!\n${result.join('\n')}`, "BLUE") options.map(async (c, x) => { await msg.react(num[x + 1]) }) } } }
  2. 然后以管理员身份运行
  3. 然后是 cmdnpm i -g expo-cli

我刚刚解决了我的问题。

答案 25 :(得分:0)

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

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

答案 26 :(得分:0)

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

答案 27 :(得分:0)

就像遇到此问题一样,可能是您的PC上存在权限问题。转到PC属性并授予您在PC上使用的任何帐户完全控制即可解决此问题。

再次命令/ usr / local在Windows上不起作用

答案 28 :(得分:0)

尝试所有方法后,无济于事。 将我的工作项目文件夹移动到其他目标位置对我来说很有效。

答案 29 :(得分:0)

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

答案 30 :(得分:0)

Windows 10,

以管理员模式运行IDE(在我的情况下为IntelliJ)并执行npm install确实可以解决问题。

如果没有IDE,则以管理员模式运行CMD并尝试执行npm install

答案 31 :(得分:0)

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

答案 32 :(得分:0)

我将节点版本更新为8.9.4,并从管理员命令提示符处再次运行必要的安装命令。它对我有用!

答案 33 :(得分: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

答案 34 :(得分:0)

重新启动笔记本电脑,然后

npm install

为我工作!

答案 35 :(得分:0)

显然,防病毒软件也可能导致此错误。就我而言,我使用Windows安全性的勒索软件保护来保护导致此错误的用户文件夹。

答案 36 :(得分:0)

尝试通过以管理员身份运行CMD来安装npm软件包。您可以访问npm install throwing error EPERM,转到有关此错误的广泛讨论。

答案 37 :(得分:0)

我也一样 我的解决方案是关闭Android Studio,AVD Manager,Visual Studio并重新安装。 我执行此命令来更新我的expo cli:

npm install -g expo-cli

答案 38 :(得分:0)

尝试npm i -g npm。 NPM 6.9版对我有用。

答案 39 :(得分:0)

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

答案 40 :(得分:-6)

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