命令

npx react-native@latest init AwesomeProject

输出

✔ Downloading template
✖ Copying template
error Error: Couldn't find the "/var/folders/8x/y10dxy554tzb5d5d2tv_rffh0000gn/T/rncli-init-template-c131XZ/node_modules/react-native/template.config.js file inside "react-native" template. Please make sure the template is valid. Read more: https://github.com/react-native-community/cli/blob/master/docs/init.md#creating-custom-template.
Error: Error: Couldn't find the "/var/folders/8x/y10dxy554tzb5d5d2tv_rffh0000gn/T/rncli-init-template-c131XZ/node_modules/react-native/template.config.js file inside "react-native" template. Please make sure the template is valid. Read more: https://github.com/react-native-community/cli/blob/master/docs/init.md#creating-custom-template
    at createFromTemplate (/Users/rmunoz/.npm/_npx/dea611a43221eddd/node_modules/@react-native-community/cli/build/commands/init/init.js:131:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.initialize [as func] (/Users/rmunoz/.npm/_npx/dea611a43221eddd/node_modules/@react-native-community/cli/build/commands/init/init.js:184:3)
    at async 命令.handleAction (/Users/rmunoz/.npm/_npx/dea611a43221eddd/node_modules/@react-native-community/cli/build/index.js:106:9)
info Run CLI with --verbose flag for more details.

我判断了/var/目录,发现/T/rncli-init-template-c131XZ/node_modules/react-native/template.config.js不存在.我试着在网上寻找自己制作的模板,但我找不到它,我真的不知道go 哪里找.

我使用了GitHub链接,但我显然不想创建自定义模板.

我确实按照文档安装了Xcode CLI工具和Ruby 2.7.6的正确版本

推荐答案

the instructions you're following的顶部有一个非常明确的警告:

注意:如果您的计算机上同时安装了yarnnpm,Reaction Native CLI将始终try 使用yarn,因此即使您使用npx实用程序,也只会使用npm安装react-native个可执行文件,其余工作将委托给yarn.您可以强制使用npm,在命令中添加--npm标志.

您需要使用--npm重新运行命令:

npx react-native@latest init AwesomeProject --npm

此外,你应该花一些时间阅读大约tags本书.观察错误消息应该指示唯一相关的是react-native,因为该命令永远不会超过运行react-native@latest init的初始阶段.

React-native相关问答推荐

防止 React Native 在上下文值更改时重新安装组件

应用管理

React Native 应用程序没有在之前的工作代码中执行任何操作就无法运行

如何将 react-native 图像从 expo-image-picker 上传到使用 multer 的 Express.js 后端

react-navigation中的React-native android后退按钮

Android Studio 为构建设置 node 目录(Cause: error=2, No such file or directory)

react-native StyleSheet 属性和选项列表

用hooks钩子react context上下文防止重新渲染

submit提交后如何让 React Native TextInput 保持焦点?

FlatList contentContainerStyle -> justifyContent: 'center' 导致滚动问题

mapDispatchToProps:有什么意义吗?

React-Native:FlatList onRefresh not called on pull up.

React Native 创建自定义组件/库

动画属性启动时 ReactNative ActivityIndi​​cator 不显示 false

更改按钮 colored颜色 onPress(切换功能)

DeviceInfo 原生模块未正确安装

React Native Android 负边距(Margins)

您将如何在 Alert 中模拟onPress?

React Native - 如何从推送通知中打开路由

React 在任何根目录中都找不到入口文件