我正在使用MacBook,当我尝试创建React Antive应用程序时,它会引发ESOCKETTIMEDOUT
错误。
我试图清洁NPM和纱线缓存,但这无济于事。
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
在慢速网络上检索大包装时也有相同的问题。如此评论所建议的,增加安装软件包的网络超时对我有用。
首先,要事先创建您的项目目录,然后在其内部创建一个具有以下内容的.yarnrc
文件:
network-timeout 600000
现在,只需像您一样从项目的父目录中运行react-native init <project_name>
命令。
这等同于运行yarn
这样的人:
yarn install --network-timeout 600000
如果可以使用npm,请使用' npm install
'&amp;它生成package-lock.json
或'yarn install --network-timeout <time in ms>
' - 生成yarn.lock
。两者都对我有用。
/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