【问题标题】:React native init is not working in new fresh projectReact native init 在新项目中不起作用
【发布时间】:2019-05-24 21:12:41
【问题描述】:

我正在尝试使用 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) }

我的堆栈是:

  • 节点:10.15.3
  • npm: 6.4.1
  • 纱线:1.16.0
  • react-native-cli: 2.0.1

【问题讨论】:

  • 您想初始化新项目或更改现有项目的 react-native 版本?
  • 请说明您使用哪个命令来创建 react native 应用程序
  • 标准方式:react-native init AppName

标签: node.js react-native npm yarnpkg


【解决方案1】:

先尝试清除纱线缓存:yarn cache clean。然后运行 react-native init ProjectName 您使用的是哪个操作系统?

更新: 解决方案:这是因为 react-native init 在另一个文件系统上运行(在这种情况下是谷歌驱动器)。将react-native init projectname 的位置更改为操作系统正在使用的默认文件系统。

【讨论】:

  • 失败,结果相同。
  • 您使用的是哪个操作系统?尝试重新安装节点,然后重试。
  • 我使用的是 Mac OS。我正在为节点使用 nvm 0.34.0,并且我已经尝试重新安装我的节点版本..
  • 该目录中是否有yarn-error.log 文件?如果是这样,您可以检查该日志文件,一个可能的原因可能是可能存在 Internet 连接问题。如果是这种情况,那么您可以尝试以下解决方案来修复:github.com/yarnpkg/yarn/issues/3227
  • 是的,有!这是跟踪:错误:ENOSYS:函数未实现,符号链接'../../../parser/bin/babel-parser.js'->'AppName/node_modules/@babel/core/node_modules/.bin /解析器'
【解决方案2】:

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

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

【讨论】:

  • 失败,结果相同。
【解决方案3】:

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

【讨论】:

    【解决方案4】:

    试试 react-native init YourProjectName

    【讨论】:

    • 你需要使用它作为npx react-native init
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-30
    • 2019-12-30
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    • 2017-02-10
    相关资源
    最近更新 更多