node.js npm 安装错误:rollbackFailedOptional

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46011546/
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:28:35  来源:igfitidea点击:

npm install Error: rollbackFailedOptional

node.jsreact-nativenpm

提问by Bipul Prasai

When I try npm installnew packages it shows me this error:

当我尝试npm install新软件包时,它向我显示此错误:

rollbackFailedOptional: verb npm-session 585aaecfe5f9a82

rollbackFailedOptional:动词 npm-session 585aaecfe5f9a82

node --version
8.4.0

npm --version
5.3.0

回答by cwtuan

Try this

尝试这个

npm config rm proxy
npm config rm https-proxy

回答by anvarik

    # first this
    > npm config rm proxy
    > npm config rm https-proxy

    # then this
    > npm config set registry http://registry.npmjs.org/

solved my problem.

解决了我的问题。

回答by miqrc

In my case I had to edit the .npmrc directly and add the proxy settings manually.

就我而言,我必须直接编辑 .npmrc 并手动添加代理设置。

proxy=http://yourorganizationproxy.com:8080
https-proxy=http://yourorganizationproxy.com:8080

Hope this helps someone.

希望这可以帮助某人。

回答by lambda

The cause for this might be your current NPM registry. Try to check for a .npmrcfile. These can be at various locations:

造成这种情况的原因可能是您当前的 NPM 注册表。尝试检查.npmrc文件。这些可以在不同的位置:

  • per-project config file (/path/to/my/project/.npmrc)
  • per-user config file (~/.npmrc)
  • global config file ($PREFIX/etc/npmrc)
  • npm builtin config file (/path/to/npm/npmrc)
  • 每个项目的配置文件 ( /path/to/my/project/.npmrc)
  • 每个用户的配置文件 ( ~/.npmrc)
  • 全局配置文件 ( $PREFIX/etc/npmrc)
  • npm 内置配置文件 ( /path/to/npm/npmrc)

Within these there can be something like

在这些中可以有类似的东西

registry=https://mycustomregistry.example.org

which will take priority over the default one (http://registry.npmjs.org/). You can delete this line in the file or use the default registry like that:

这将优先于默认值 ( http://registry.npmjs.org/)。您可以删除文件中的这一行或使用默认注册表,如下所示:

npm <command> --registry http://registry.npmjs.org/

回答by AnotherLongUsername

Most likely to be npm registry cannot be reached by npm. Check npm proxy configuration

最有可能是 npm 注册表无法通过 npm 访问。检查 npm 代理配置

I had exactly the same issue on Windows Server 2008 R2. I suspected Internet Explorer's Enhanced Security Configuration at first but after turning that off with no success the issue turned out to be that npm was not configured to use my corporate proxy connection to the internet.

我在 Windows Server 2008 R2 上遇到了完全相同的问题。我起初怀疑 Internet Explorer 的增强安全配置,但在将其关闭但没有成功后,问题是 npm 未配置为使用我的公司代理连接到 Internet。

It turns out that npm does not use the proxy settings in effect via Internet Options > Connections tab > LAN settings where the server is set to 'Automatically detect settings'. Being set to automatically detect settings does not guarantee that a proxy is indeed being used, it just means that Windows will automatically configure proxy settings for Internet Explorer if it finds a special'wpad.dat' file at http://wpad.[yourdomain.com]/wpad.dat.

事实证明,npm 不使用通过 Internet 选项 > 连接选项卡 > LAN 设置生效的代理设置,其中服务器设置为“自动检测设置”。设置为自动检测设置并不能保证确实使用了代理,这只是意味着如果 Windows 在http://wpad.[yourdomain]找到特殊的“wpad.dat”文件,它会自动为 Internet Explorer 配置代理设置.com]/wpad.dat

You can test whether a wpad.dat file is in use in your organisation by typing the following into a web browser.

您可以通过在 Web 浏览器中键入以下内容来测试您的组织中是否正在使用 wpad.dat 文件。

http://wpad.[yourcompany.domain]/wpad.dat

If no file is available then it is likely you are not using an organization-wide proxy. If one does get returned to the browser then...

如果没有可用的文件,那么您可能没有使用组织范围的代理。如果确实返回到浏览器,那么......

Toward the bottom of this file, you should see a line saying

在这个文件的底部,你应该看到一行说

PROXY <host:port>;

It might be repeated if you have multiple proxies available. The host and port are needed in order to tell npm to use the proxy settings like so:

如果您有多个可用代理,则可能会重复。需要主机和端口才能告诉 npm 使用代理设置,如下所示:

npm config set proxy http://[host]:[port]

and

npm config set https-proxy http://[host]:[port]

For example if your proxy is at my.proxy.com on port 8080 then the npm commands would be:

例如,如果您的代理位于 my.proxy.com 的 8080 端口,那么 npm 命令将是:

npm config set proxy http://my.proxy.com:8080
npm config set https-proxy http://my.proxy.com:8080

Once I had told npm which proxy to use all started working in I was able to run the install commands without a problem.

一旦我告诉 npm 使用哪个代理开始工作,我就可以毫无问题地运行安装命令。

Thanks to the following postfor help with the wpad file discovery.

感谢以下帖子对 wpad 文件发现的帮助。

回答by Anil

I tried following options to fix this issue and it worked.

我尝试了以下选项来解决这个问题,它奏效了。

  1. Uninstall Node.js version 8.
  2. Install Node.js version 6.11.4
  3. Use the registry optionalong with command to install any package.
  1. 卸载 Node.js 版本 8。
  2. 安装 Node.js 版本 6.11.4
  3. 使用注册表选项和命令来安装任何软件包。

For example to install express I used following command.

例如,我使用以下命令安装 express。

npm install express --registry http://registry.npmjs.org/

or

或者

npm install express -g --registry http://registry.npmjs.org/

If you want to install locally in any specific folder then use below command. Below command will install express on path C:\Sample\Example1.

如果要在任何特定文件夹中本地安装,请使用以下命令。下面的命令将在 path 上安装 express C:\Sample\Example1

C:\Sample1\Example1> npm install /Sample/Example1 express --registry http://registry.npmjs.org/

Note:If you are installing locally in a specific location then first go to that directory using command and then run above command. If you are not inside that directory and giving only path in command that will not work.

注意:如果您在特定位置本地安装,则首先使用命令转到该目录,然后运行上面的命令。如果您不在该目录中并且仅在命令中提供路径,则该路径将不起作用。

If you get package.jsonmissing error then run below command before installing package locally

如果您遇到package.json错误,请在本地安装软件包之前运行以下命令

C:\Sample\Example1> npm init

above command will create package.jsonfile. No need to provide any data. just hit enter.

上面的命令将创建package.json文件。无需提供任何数据。只需点击进入。

Note:If you are behind a firewall then you may need to set a proxy.

注意:如果您在防火墙后面,那么您可能需要设置代理。

回答by Rails Developer

Hi I'm also new to react and I also faced this problem after so many trouble I found solution: Just run in your command prompt or terminal :

嗨,我也是新来的,经过这么多麻烦我也遇到了这个问题,我找到了解决方案:只需在命令提示符或终端中运行:

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

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

This will resolve your problem. Reference link: http://blog.csdn.net/zhalcie2011/article/details/78726679

这将解决您的问题。参考链接:http: //blog.csdn.net/zhalcie2011/article/details/78726679

回答by Rudra

Make sure you can access the corporate repository you configured in npm is available.Check you VPN connection.

确保您可以访问您在 npm 中配置的公司存储库可用。检查您的 VPN 连接。

Else reset it back to default repository like below.

否则将其重置回默认存储库,如下所示。

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

Good Luck!!

祝你好运!!

回答by Alex Evseenko

If you have access to the registry but the error is still occurred nothing mentioned above wouldn't work. I noted that this problem is only applicable for local project's installation (i.e. if you use -g to global install everything is working fine).

如果您有权访问注册表但仍然发生错误,则上述任何内容都不起作用。我注意到这个问题仅适用于本地项目的安装(即,如果您使用 -g 进行全局安装,一切正常)。

What's resolved the problem for me: just remove an entry regarding a package you're going to install from a project's package.json file. After that next call to npm will work and install the package successfully.

什么为我解决了问题:只需从项目的 package.json 文件中删除有关您要安装的包的条目。之后对 npm 的下一次调用将工作并成功安装包。

回答by Santhosh K Thadka

The following commands resolved my issue:

以下命令解决了我的问题:

npm config set proxy http://yourproxyurl.com:8080  (you need to enter your or your company proxy URL and 8080 should be replaced by your proxy port)

npm config set https-proxy http://yourproxyurl.com:8080