Yarn在网络连接方面出现了问题。

48

今天早些时候,我尝试使用yarn安装一个软件包,但是遇到了以下问题

yarn install
yarn install v1.9.4
[1/4]   Resolving packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
error An unexpected error occurred: "https://registry.yarnpkg.com/eslint: getaddrinfo ENOTFOUND     registry.yarnpkg.com registry.yarnpkg.com:443".
info If you think this is a bug, please open a bug report with the information provided in "/Users/daviddragovacz/Documents/GitHub/react-    project-one/dragi/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

有谁知道如何修复这个问题吗? 我的网络似乎很好,一点也不慢。

我尝试了每个软件包都遇到了同样的问题。

package.json

{
    "name": "dragi",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "axios": "^0.18.0",
        "prop-types": "^15.6.2",
        "react": "^16.4.2",
        "react-dom": "^16.4.2",
        "react-redux": "^5.0.7",
        "react-router": "^4.3.1",
        "react-router-dom": "^4.3.1",
        "react-scripts": "1.1.5",
        "redux": "^4.0.0",
        "redux-devtools-extension": "^2.13.5",
        "redux-thunk": "^2.3.0",
        "semantic-ui-css": "^2.3.3",
        "semantic-ui-react": "^0.82.3",
        "validator": "^10.7.0"
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject",
        "lint": "eslint src"
    },
    "devDependencies": {
        "eslint": "^5.5.0",
        "eslint-config-airbnb": "^17.1.0",
        "eslint-config-prettier": "^3.0.1",
        "eslint-plugin-import": "^2.14.0",
        "eslint-plugin-jsx-a11y": "^6.1.1",
        "eslint-plugin-prettier": "^2.6.2",
        "eslint-plugin-react": "^7.11.1",
        "prettier": "^1.14.2"
    },
    "proxy": "http://localhost:8080"
}

另外需要注意的是:npm i 可以正常工作,只有 yarn 会出现问题。


请问您能否分享一下您的 package.json 文件呢? - Adeel Imran
很遗憾,Yarn没有任何调试信息。能够看到它所遇到的网络问题将是很好的。 - user959690
使用 Node 10 或更高版本解决了我的“网络连接”问题。 - Troglo
25个回答

71

1
仍然是一样的不幸.. 谢谢你的提示! :) - dragi
还是一样的..我查看了https://status.npmjs.org/,它显示目前有些问题,注册表读取现在有一些中断。这可能是原因吗? - dragi
我不认为那是原因,你能把你的 package.json 文件也放在问题中吗?我想看一下。 - Adeel Imran
嘿,我添加了 package.json 文件。 - dragi
这个答案为我节省了很多时间,因为在第一个树莓派版本上使用yarn install会由于网络和磁盘写入限制(树莓派第一个版本)而导致超时异常。谢谢老兄。 - Ashbay
显示剩余3条评论

16

1
那个标志在哪里有文档记录?https://yarnpkg.com/en/docs/cli/或https://yarnpkg.com/en/docs/cli/install上都没有。 - jcollum
1
我只能在 yarn --help 中找到它。 - ramki
2
默认值(https://github.com/yarnpkg/yarn/blob/3119382885ea373d3c13d6a846de743eca8c914b/src/constants.js#L40)目前为30,000,即30秒。 - Ninjakannon

9

我曾遇到同样的问题,按照以下步骤解决:

运行终端命令

  1. 清空npm缓存
  2. npm cache clean --force
  3. 设置http_proxy=
  4. 设置https_proxy=
  5. yarn config delete proxy
  6. npm config rm https-proxy
  7. npm config rm proxy
  8. 重新启动终端
  9. yarn
  10. yarn –network-timeout 100000

重新启动终端。

对我有效。#愉快编码


5
如果您正在使用WSL来运行Linux,只需在C:\Windows\System32\drivers\etc\hosts中添加当前IP域名,例如:
104.16.21.35    registry.yarnpkg.com

3

我遇到了另一个错误,但是网络连接问题相同。我阅读了这个帖子:https://github.com/yarnpkg/yarn/issues/15

最终我卸载/重新安装了node/npm,问题得到了解决。也许你的node安装有问题?


使用 Node 10 或更高版本解决了我的“网络连接”问题。 - Troglo

2
这是我成功的方法:

这是我的解决方案:

brew reinstall node

brew reinstall yarn

npm cache clean --force
 && yarn cache clean
 && yarn config delete proxy
 && yarn config delete https-proxy
 && yarn config delete registry

然后立即重新启动


2

可能图书馆最初使用的是npm而不是yarn。在我的情况下,我必须使用npm安装所有内容。我删除了yarn.lock文件,然后:

npm install

2

在bash环境中使用代理导致了同样的问题。

运行命令unset HTTP_PROXY HTTPS_PROXY ALL_PROXY后,解决了这个问题。


取消所有代理环境变量解决了这个问题,在我的情况下。 对于我来说,包括上面的命令; $ unset http_proxy https_proxy - agfe2

1

检查您的互联网速度/连接强度。我在使用不稳定的公共WiFi时遇到了这个问题。注意到每次尝试时都会出现不同的错误包。一旦我获得了更快/更稳定的互联网,这个问题就解决了。(这些包对于我的差劲连接来说太大了)。


这是我的问题。我正在尝试在酒店里运行yarn --production,结果出现了与原帖相同的错误。但是,将我的代码复制到远程服务器上并在那里运行yarn --production解决了这个问题。 - MikeyE

1
在我的情况下,有一个隐藏文件.npmrc,其中注册表指向另一个私有网络中的位置,而我的网络无法访问。一旦我注释掉了该文件中与私有网络相关的条目,yarn install就开始工作了。此外,生成了yarn-error.log,其中包含这些信息。

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