npx创建项目时,error fetch failed.TypeError: fetch failed
npx创建项目时,报以下错误:
error fetch failed.
TypeError: fetch failedat node:internal/deps/undici/undici:12345:11at process.processTicksAndRejections (node:internal/process/task_queues:95:5)at async getTemplateVersion (C:\Users\ymt30\AppData\Local\npm-cache\_npx\2788f5fbd47acb89\node_modules\@react-native-community\cli\build\tools\npm.js:117:16)at async createTemplateUri (C:\Users\ymt30\AppData\Local\npm-cache\_npx\2788f5fbd47acb89\node_modules\@react-native-community\cli\build\commands\init\version.js:53:29)at async createProject (C:\Users\ymt30\AppData\Local\npm-cache\_npx\2788f5fbd47acb89\node_modules\@react-native-community\cli\build\commands\init\init.js:338:23)at async Object.initialize [as func] (C:\Users\ymt30\AppData\Local\npm-cache\_npx\2788f5fbd47acb89\node_modules\@react-native-community\cli\build\commands\init\init.js:418:7)at async Command.handleAction (C:\Users\ymt30\AppData\Local\npm-cache\_npx\2788f5fbd47acb89\node_modules\@react-native-community\cli\build\index.js:124:9)
info Run CLI with --verbose flag for more details.
创建时,是按照官方的命令创建npm uninstall -g react-native-cli @react-native-community/cli
检查了sdk版本是17,node版本20+,react-native-cli版本2.+,版本方面没有问题,但忽略了npx设置源。安装官方指导,设置后,再创建正常。
# 使用nrm工具切换淘宝源
npx nrm use taobao# 如果之后需要切换回官方源可使用
npx nrm use npm