React native init 在新项目中不起作用

React native init is not working in new fresh project

我正在尝试使用 react-native 0.59.8 创建一个新项目,但失败了。

我尝试了不同版本的 react-native,所以我认为问题出在我使用的 yarn、node 或 npm 版本上。

{ Error: Command failed: yarn add react-native --exact
    at checkExecSyncError (child_process.js:616:11)
    at execSync (child_process.js:653:13)
    at run (/Users/francesco/.nvm/versions/node/v10.15.3/lib/node_modules/react-native-cli/index.js:294:5)
    at createProject (/Users/francesco/.nvm/versions/node/v10.15.3/lib/node_modules/react-native-cli/index.js:249:3)
    at init (/Users/francesco/.nvm/versions/node/v10.15.3/lib/node_modules/react-native-cli/index.js:200:5)
    at Object.<anonymous> (/Users/francesco/.nvm/versions/node/v10.15.3/lib/node_modules/react-native-cli/index.js:153:7)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12) }

我的堆栈是:

试试看 react-native 初始化你的项目名称

最好使用 React-native 0.57 版本以获得更好的稳定性,并确保您的节点模块大于版本 10 并正确环境变量

react-native init ProjectName --version react-native@0.57.8

首先尝试清除纱线缓存:yarn cache clean。那么运行 react-native init ProjectName 您正在使用哪个 OS?

更新: 解决方案:这是因为 react-native init 在另一个文件系统上 运行ning(在本例中为 google 驱动器)。将 react-native init projectname 的位置更改为 OS 使用的默认文件系统有效。

如果您的 $ node -v 低于 12,请更新至 12 或更新版本。

截至 2022 年 5 月,此版本适用于我。

npx react-native init deeplinktest --version 0.67.4