npm react-native init给出ESOCKETTIMEDOUT错误

a1o7rhls  于 2023-05-18  发布在  React
关注(0)|答案(3)|浏览(209)

我正在使用MacBook,当我尝试创建一个React Native应用程序时,它会抛出ESOCKETTIMEDOUT错误。
我尝试过清理npm和yarn缓存,但没有帮助。

react-native init AwesomeProject
This will walk you through creating a new React Native project in /Users/gaurang.shah/Documents/personal/code/mobile/AwesomeProject
Using yarn v1.13.0
Installing react-native...
yarn add v1.13.0
info No lockfile found.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching 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/lodash/-/lodash-4.17.11.tgz: ESOCKETTIMEDOUT".
info If you think this is a bug, please open a bug report with the information provided in "/Users/gaurang.shah/Documents/personal/code/mobile/AwesomeProject/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

我可以通过浏览器下载https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz文件,所以它不可能是网络问题。

Stacktrace

Yarn version:
  1.13.0

Node version:
  11.10.0

Platform:
  darwin x64

Trace:
  Error: https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz: ESOCKETTIMEDOUT
      at ClientRequest.<anonymous> (/usr/local/Cellar/yarn/1.13.0/libexec/lib/cli.js:130024:19)
      at Object.onceWrapper (events.js:285:13)
      at ClientRequest.emit (events.js:197:13)
      at TLSSocket.emitRequestTimeout (_http_client.js:669:40)
      at Object.onceWrapper (events.js:285:13)
      at TLSSocket.emit (events.js:197:13)
      at TLSSocket.Socket._onTimeout (net.js:447:8)
      at listOnTimeout (timers.js:327:15)
      at processTimers (timers.js:271:5)

npm manifest:
  {"name":"AwesomeProject","version":"0.0.1","private":true,"scripts":{"start":"node node_modules/react-native/local-cli/cli.js start"}}

yarn manifest:
  No manifest

Lockfile:
  No lockfile
vc6uscn9

vc6uscn91#

在缓慢的网络上检索大包时遇到了同样的问题。正如这条评论所建议的,增加安装软件包的网络超时对我来说很有效。
首先,预先创建项目目录,然后在其中创建一个.yarnrc文件,其内容如下:

network-timeout 600000

现在,只需像您所做的那样从项目的父目录运行react-native init <project_name>命令。
它相当于像这样运行yarn

yarn install --network-timeout 600000
nxowjjhe

nxowjjhe2#

如果可以使用npm,请使用' npm install ',它生成package-lock.json或' yarn install --network-timeout <time in ms> ',它生成yarn.lock。两个都适合我。

relj7zay

relj7zay3#

/opt/homebrew/bin/npx --yes --package react-native-cli react-native init hello
yes
prompt: Directory hello already exists. Continue?:  (no) (node:54861) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
yes
This will walk you through creating a new React Native project in /Users/xm/WebstormProjects/hello
Using yarn v3.5.1
Installing react-native...
➤ YN0000: ┌ Resolution step
➤ YN0032: │ fsevents@npm:2.3.2: Implicit dependencies on node-gyp are discouraged
➤ YN0061: │ uglify-es@npm:3.3.10 is deprecated: support for ECMAScript is superseded by `uglify-js` as of v3.13.0
➤ YN0001: │ RequestError: Socket connection timeout
    at ClientRequest.<anonymous> (/Users/xm/.cache/node/corepack/yarn/3.5.1/yarn.js:195:14340)
    at Object.onceWrapper (node:events:626:26)
    at ClientRequest.emit (node:events:523:35)
    at o.emit (/Users/xm/.cache/node/corepack/yarn/3.5.1/yarn.js:190:90286)
    at TLSSocket.socketErrorListener (node:_http_client:495:9)
    at TLSSocket.emit (node:events:511:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
    at new NodeError (node:internal/errors:399:5)
    at internalConnectMultiple (node:net:1099:20)
    at Timeout.internalConnectMultipleTimeout (node:net:1638:3)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7)
➤ YN0000: └ Completed in 8s 421ms
➤ YN0000: Failed with errors in 8s 422ms
➤ YN0061: @npmcli/move-file@npm:2.0.1 is deprecated: This functionality has been moved to @npmcli/fs
Error: Command failed: yarn add react-native --exact
    at checkExecSyncError (node:child_process:885:11)
    at execSync (node:child_process:957:15)
    at run (/Users/xm/.npm/_npx/10e3bde211213596/node_modules/react-native-cli/index.js:294:5)
    at createProject (/Users/xm/.npm/_npx/10e3bde211213596/node_modules/react-native-cli/index.js:249:3)
    at /Users/xm/.npm/_npx/10e3bde211213596/node_modules/react-native-cli/index.js:217:7
    at /Users/xm/.npm/_npx/10e3bde211213596/node_modules/prompt/lib/prompt.js:316:32
    at /Users/xm/.npm/_npx/10e3bde211213596/node_modules/async/lib/async.js:142:25
    at assembler (/Users/xm/.npm/_npx/10e3bde211213596/node_modules/prompt/lib/prompt.js:313:9)
    at /Users/xm/.npm/_npx/10e3bde211213596/node_modules/prompt/lib/prompt.js:322:32 {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 54864,
  stdout: null,
  stderr: null
}
Command `yarn add react-native --exact` failed.
Done

相关问题