0

在 FB 的 git 页面上,我一直在了解开始使用 React Native 的初始步骤。https://facebook.github.io/react-native/docs/getting-started

在此过程中,使用 nxp 或 npm 安装的 CLI,我得到了流动错误。

[!] Invalid `Podfile` file: [!] /Users/allen/.nvm/versions/node/v12.14.1/bin/node -e console.log(require('@react-native-community/cli').bin);

internal/modules/cjs/loader.js:796
    throw err;
    ^

Error: Cannot find module '@react-native-community/cli'
Require stack:
- /Volumes/BLUE/workspace-blue/react_native-blue/test/ios/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
    at Function.Module._load (internal/modules/cjs/loader.js:686:27)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at [eval]:1:13
    at Script.runInThisContext (vm.js:116:20)
    at Object.runInThisContext (vm.js:306:38)
    at Object.<anonymous> ([eval]-wrapper:9:26)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at evalScript (internal/process/execution.js:80:25) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Volumes/BLUE/workspace-blue/react_native-blue/test/ios/[eval]' ]
}

这发生在 cocoapods 安装期间。文档说:

如果您之前安装了全局 react-native-cli 包,请将其删除,因为它可能会导致意外问题。

但无论安装了什么或用于创建起始文件,都会发生这种情况。

在 Podfile 中有这些行:

platform :ios, '13.0' # <- this was 9.0 but I changed to 13.0
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

如果我在项目中本地执行 npm install @react-native-commuinty/cli 然后pod install一切正常。我应该将 CLI 路径更改为我的 npm 目录的路径吗?如果文档说在没有安装 react-native CLI 时它不应该有任何问题,那么为什么我需要安装它才能pod install正常工作?

环境:

  • macOS 10.15

  • 节点 12.14.1

  • ruby ruby​​ 2.6.3p62(2019-04-16 修订版 67580)[universal.x86_64-darwin19](尝试使用 rbenv 2.5)

  • xcode-选择版本 2373。

4

1 回答 1

0

它需要是本地的。当你进入

npx react-native init [project name]

它将在本地添加。

https://facebook.github.io/react-native/docs/getting-started

这个官方链接建议:


如果您之前安装了全局 react-native-cli 包,请将其删除,因为它可能会导致意外问题。


于 2020-02-14T10:22:19.397 回答