创建React应用程序时如何解决npm ERR_SOCKET_TIMEOUT错误?

tns*_*day 1 sockets npm create-react-app

我使用 npx create-react-app 来引导我的项目。安装过程崩溃并显示:

npm ERR! code ERR_SOCKET_TIMEOUT
npm ERR! errno ERR_SOCKET_TIMEOUT
npm ERR! network Invalid response body while trying to fetch https://registry.npmjs.org/@babel%2fhelper-compilation-targets: Socket timeout
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'
Run Code Online (Sandbox Code Playgroud)

我用 Chrome 浏览器打开该网址,效果很好:

在此输入图像描述

我该如何解决这个问题?

小智 5

我遇到了同样的错误。\n解决方案是更改超时的定义。

\n

它对我来说就像一个魅力 \xe2\x9c\xa8

\n

要更改超时,\n运行以下两个命令:

\n

npm config set fetch-retry-mintimeout 20000

\n

npm config set fetch-retry-maxtimeout 120000

\n

我希望这有帮助。

\n