简体   繁体   English

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

[英]React native init is not working in new fresh project

I'm trying to create a fresh project with react-native 0.59.8 but is failing.我正在尝试使用 react-native 0.59.8 创建一个新项目,但失败了。

I have tried different versions of react-native so I think the problem is in yarn, node or npm versions that i'm using.我尝试了不同版本的 react-native,所以我认为问题出在我正在使用的纱线、节点或 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) }

My stack is:我的堆栈是:

  • node: 10.15.3节点:10.15.3
  • npm: 6.4.1 npm:6.4.1
  • yarn: 1.16.0纱线:1.16.0
  • react-native-cli: 2.0.1反应本机 cli: 2.0.1

Try clearing yarn cache first : yarn cache clean .首先尝试清除纱线缓存: yarn cache clean Then run react-native init ProjectName Which OS you are using ?然后运行react-native init ProjectName您正在使用哪个操作系统?

Update: Solution: It was because react-native init was running on another file system(google drive in this case).更新:解决方案:这是因为 react-native init 正在另一个文件系统上运行(在这种情况下是谷歌驱动器)。 Changing the location of react-native init projectname to default file system that OS is using worked.react-native init projectname的位置更改为操作系统正在使用的默认文件系统。

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

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

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

This version works for me as of May 2022.截至 2022 年 5 月,此版本对我有效。

npx react-native init deeplinktest --version 0.67.4

尝试使用 react-native init YourProjectName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM