首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用npx创建react应用程序时的ERR_SOCKET_TIMEOUT

使用npx创建react应用程序时的ERR_SOCKET_TIMEOUT
EN

Stack Overflow用户
提问于 2022-04-18 12:55:22
回答 2查看 1.3K关注 0票数 1
代码语言:javascript
复制
PS C:\Users\User> npx create-react-app client

Creating a new React app in C:\Users\User\client.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

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/eslint: 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'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User\AppData\Local\npm-cache\_logs\2022-04-18T02_58_18_148Z-debug-0.log

Aborting installation.
  npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.

Deleting generated file... package.json
Deleting client/ from C:\Users\User
Done.
npm ERR! code 1
npm ERR! path C:\Users\User
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c create-react-app "client"

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User\AppData\Local\npm-cache\_logs\2022-04-18T02_58_06_939Z-debug-0.log
PS C:\Users\User>
EN

回答 2

Stack Overflow用户

发布于 2022-07-11 10:08:24

在全球安装create时,npx create-react-app app-namecreate-react-app app-name也遇到了同样的问题。

与纱线不同的是,npm对缓慢的互联网连接几乎没有容忍度。我甚至尝试使用来自终端的命令重置配置中的超时值属性:

代码语言:javascript
复制
npm config set timeout 240000

还有,试过

代码语言:javascript
复制
npm config set fetch-retry-mintimeout 120000

代码语言:javascript
复制
npm config set fetch-retry-maxtimeout 240000

这些都不适合我。

最后,我通过简单地使用

代码语言:javascript
复制
yarn create react-app app-name

在缓慢的连接上几乎不会失败,因为它总是尝试重新连接,并从停止的地方继续前进。

使用npm在全球范围内安装最新版本的纱线,使用:

代码语言:javascript
复制
npm i -g yarn@latest

检查纱线是否已安装

代码语言:javascript
复制
yarn -v

然后在所需的项目目录中运行yarn create react-app your-app-name

票数 2
EN

Stack Overflow用户

发布于 2022-04-18 17:16:22

这对我有帮助

npm -g列表

安装-g创建-反应-应用程序

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71912097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档