node.js 安装任何软件包时出现 npm rollbackFailedOptional 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50315520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:47:53  来源:igfitidea点击:

npm rollbackFailedOptional error when install any package

node.jsnpm

提问by prodigy

I have a problem when installing any npmpackages. here is my error:

安装任何npm软件包时出现问题。这是我的错误:

rollbackFailedOptional: verb npm-session xxxxxxxxxxx

rollbackFailedOptional: verb npm-session xxxxxxxxxxx

for resolving this I do some stuff but I still get the same error.

为了解决这个问题,我做了一些事情,但我仍然遇到同样的错误。

I put registry=http://registry.npmjs.org/in .npmrcfile in my user folder and also run following commands:

我放进registry=http://registry.npmjs.org/去。npmrc文件在我的用户文件夹中,并运行以下命令:

npm config rm proxy
npm config rm https-proxy

I try to solve the problem in node 8.11.1and node 10.1.0and my npm version is 5.6.0.

我尝试解决 node8.11.1和 node 中的问题10.1.0,我的 npm 版本是5.6.0.

Why this problem occurs and how can resolve that?

为什么会出现这个问题,如何解决?

Update:npm config list:

更新:npm 配置列表:

; cli configs
metrics-registry = "http://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.6.0 node/v8.11.1 win32 x64"

; userconfig C:\Users\me\.npmrc
https-proxy = "https://username:[email protected]:6050/"
proxy = "http://username:[email protected]:6050/"
registry = "http://registry.npmjs.org/"

; builtin config undefined
prefix = "C:\Users\me\AppData\Roaming\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\Users\me
; HOME = C:\Users\me
; "npm config ls -l" to show all defaults.

回答by d3t0x

Can you try enter this and then re run:

你可以尝试输入这个然后重新运行:

npm config set registry http://registry.npmjs.org/

回答by Nuhman

I've tried almost all methods posted in various forums like stackoverflow, github-issues etc.. but nothing seemed to work. Here are the commands I've executed in order which I encourage you to try because it worked for many people (but not me):

我已经尝试了在各种论坛(如 stackoverflow、github-issues 等)中发布的几乎所有方法,但似乎没有任何效果。以下是我按顺序执行的命令,我鼓励您尝试这些命令,因为它适用于许多人(但不适用于我):

  • npm config rm proxy
  • npm config rm https-proxy
  • npm config set https-proxy https://username:[email protected]:6050
  • npm config set proxy http://username:[email protected]:6050
  • npm config set registry http://registry.npmjs.org/
  • npm config rm proxy
  • npm config rm https-proxy
  • npm config set https-proxy https://username:[email protected]:6050
  • npm config set proxy http://username:[email protected]:6050
  • npm config set registry http://registry.npmjs.org/

And then when trying to install the package npm install -g express- it failed.

然后在尝试安装软件包时npm install -g express- 它失败了。

However, when I tried to run npm install npm@latest -git miraculouslyexecuted and installed fine! Then running npm install -g expressagain worked perfectly fine too.

但是,当我尝试运行npm install npm@latest -g它时,它奇迹般地执行并安装得很好!然后npm install -g express再次运行也完全正常。

TL;DR: updating npm to the latest version solved the issue (currently 6.0.1)

TL;DR:将 npm 更新到最新版本解决了这个问题(目前是 6.0.1)

回答by Someindra Singh

I solved this problem by setting the proxy property of config.

我通过设置 config 的 proxy 属性解决了这个问题。

The most likely reason you might be facing this problem is if you are behind a proxy.

您可能面临此问题的最可能原因是您是否使用代理。

You may follow the following steps to solve the issue

您可以按照以下步骤解决问题

Type:

类型:

npm config get proxy

If you get null. It means the proxy is not set.

如果你得到空值。这意味着未设置代理。

Go to Internet Explorer->Tools->Internet Options-> LAN Settings Here you would find your proxy address and port under proxy server. If you have your username and password then do the following

转到 Internet Explorer->工具->Internet 选项-> LAN 设置 在这里您可以在代理服务器下找到您的代理地址和端口。如果您有用户名和密码,请执行以下操作

npm config set proxy http://your-username:your-password@Proxy-address:port-number

After this you can use npm install.

在此之后,您可以使用 npm install。

回答by ankita

I am installing npm package behind corporate proxy. following steps resolved the issue for me -

我正在公司代理后面安装 npm 包。以下步骤为我解决了问题-

  1. Remove http and https proxy - npm config rm proxy and npm config rm https-proxy
  2. Set registry - npm config set registry http://registry.npmjs.org/
  3. Set http and https proxy - npm config set proxy yourCorporateProxyAddress:port, npm config set https-proxy yourCorporateProxyAddress:port
  4. Install package - npm install packageName
  1. 删除 http 和 https 代理 - npm config rm proxy 和 npm config rm https-proxy
  2. 设置注册表 - npm config 设置注册表http://registry.npmjs.org/
  3. 设置 http 和 https 代理 - npm config set proxy yourCorporateProxyAddress:port, npm config set https-proxy yourCorporateProxyAddress:port
  4. 安装包 - npm install packageName

回答by Ruksar Madalmatti

I was getting same error in user command prompt then tried in PowerShell as an admin and it worked.

我在用户命令提示符中遇到相同的错误,然后以管理员身份在 PowerShell 中尝试,并且成功了。

Run the following commands in Windows PowerShell as Administrator:

以管理员身份在 Windows PowerShell 中运行以下命令:

npm config set https-proxy https://username:[email protected]:6050

npm config set proxy http://username:[email protected]:6050

config set registry http://registry.npmjs.org/