当安装任何包时,出现npm rollbackFailedOptional错误

11

我在安装任何 npm 包时遇到了问题,以下是我的错误:

rollbackFailedOptional: verb npm-session xxxxxxxxxxx

为了解决这个问题,我做了一些尝试,但仍然遇到了相同的错误。

我在我的用户文件夹中的 .npmrc 文件中添加了 registry=http://registry.npmjs.org/,并运行了以下命令:

npm config rm proxy
npm config rm https-proxy

我尝试解决在node 8.11.1和node 10.1.0中出现的问题,我的npm版本是5.6.0

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

更新: 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:password@proxy.company.com:6050/"
proxy = "http://username:password@proxy.company.com: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.

https-proxy 中,您正在使用 https://,请改用 http:// - Vineet Jain
10个回答

8

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

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

7

我已经尝试了各种论坛(如stackoverflow、github-issues等)上发布的几乎所有方法,但似乎都没有起作用。以下是我执行的命令顺序,我鼓励你也尝试一下,因为它对许多人有效(但对我无效):

  • npm config rm proxy
  • npm config rm https-proxy
  • npm config set https-proxy https://username:password@proxy.company.com:6050
  • npm config set proxy http://username:password@proxy.company.com:6050
  • npm config set registry http://registry.npmjs.org/

然后当尝试安装包npm install -g express时,它失败了。

然而,当我尝试运行npm install npm@latest -g时,它竟然执行并成功安装了!然后再次运行npm install -g express,也完美地工作了。

简而言之:将npm更新到最新版本解决了这个问题(当前版本为6.0.1)。


我无法安装最新版本的 nmp - prodigy
你是否在代理后面?如果是,请运行 npm config list 命令,并确保 proxyhttps-proxy 变量已正确设置。 - Nuhman
是的,我更新了我的问题,请再看一遍。 当我在局域网设置中检查代理服务器时,“地址”是proxy.xxx.yy,“端口”是8080。 - prodigy
我想我已经回答了你的问题。是的,我在代理后面。 - prodigy
1
npm install npm@latest -gnpm update,然后跟着 npm install,这些步骤解决了我的问题。这个问题是在我更新我的 Mac 到 Catalina 之后开始出现的。 - kenef
显示剩余4条评论

3

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

  1. 移除http和https代理 - npm config rm proxy 和 npm config rm https-proxy
  2. 设置注册表 - npm config set registry http://registry.npmjs.org/
  3. 设置http和https代理 - npm config set proxy yourCorporateProxyAddress:portnpm config set https-proxy yourCorporateProxyAddress:port
  4. 安装包 - npm install packageName

我不知道在我的公司应该使用哪些代理,但是当我关闭VPN时,我可以在自己的网络上安装。 - Carl Walsh

1
我曾在用户命令提示符中遇到相同的错误,后来以管理员身份在PowerShell中尝试,结果成功了。
请以管理员身份在Windows PowerShell中运行以下命令:
npm config set https-proxy https://username:password@proxy.company.com:6050

npm config set proxy http://username:password@proxy.company.com:6050

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

1

首先这个

npm config rm proxy
npm config rm https-proxy

然后这个

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

然后安装包。
npm install packageName

PS:请确保您的网络连接正确。


1

我曾经通过在使用公司机器时指向正确的代理来解决这个相同的问题。无需管理员权限!

以下是我的步骤:

  1. 按照此处链接的步骤获取正确的代理地址!将代理地址复制/粘贴到记事本中。您将在下一步中使用相同的代理设置“proxy”和“proxy-https”参数。

  2. 在命令窗口中执行以下2个命令,将下面的<contents>替换为上一步中获取的代理地址:

    • npm config set proxy http://<proxy-server-url:port>
    • npm config set https-proxy http://<proxy-server-url:port>

注意:根据source,我从“http://<username><password>@<proxy-server-url:port>”模板中省略了“用户名”和“密码”字段,这通常可以成功运行9次,对我来说完美无缺。

  1. 从命令行导航到您的项目文件夹并执行“npm install <package name(s)>”。安装应该成功。

1

我通过设置配置的代理属性解决了这个问题。

你可能遇到这个问题的最有可能的原因是你在代理后面。

你可以按照以下步骤解决这个问题:

输入:

npm config get proxy

如果您获得了null,这意味着代理未设置。
前往Internet Explorer->工具->Internet选项->LAN设置,在此处您将在代理服务器下找到您的代理地址和端口。如果您有用户名和密码,请执行以下操作。
npm config set proxy http://your-username:your-password@Proxy-address:port-number

完成后,您可以使用npm install命令。


0

我在安装npm包时遇到了同样的问题。通过添加一些代理配置解决了问题。

前往用户->“你的用户名”-> 使用文本编辑器打开 .npmrc -> 添加以下两行

https-proxy=http://username:password@proxyUrl:port/
proxy=http://username:password@proxyUrl:port

修改用户名和密码,设置您的用户信息。 根据您的需求修改代理URL和端口。

这对我起作用了!


0

我有过相同的问题!

重新安装最新的32位nodejs对我很有帮助。

需要注意的是,我的网络上没有代理。有时当我遇到这个问题时,重新连接到我的WiFi,这也有时可以解决问题。


0

我在尝试从Github安装时遇到了同样的问题。问题是由于package.json中脚本和钩子的错误使用导致的。


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