简体   繁体   English

React-Native 构建成功 - 本机模块不能为空(iOS)

[英]React-Native Build Succeeded - Native module cannot be null (iOS)

I am running a native-react app on my local El Capitan Mac OS X machine.我在本地 El Capitan Mac OS X 机器上运行本机反应应用程序。 I am trying to get it to run in simulator for iOS.我试图让它在 iOS 模拟器中运行。

The build is succeeding but I am seeing a red screen with the words: Native module cannot be null.构建成功,但我看到一个红色屏幕,上面写着:本机模块不能为空。

I am seeing this error in console:我在控制台中看到此错误:

NotFoundError: Cannot find entry file global code@http://localhost:8081/index.ios.js in any of the roots: ["/Users/User/f8app"]
    at DependencyGraph._getAbsolutePath (/Users/User/f8app/node_modules/node-haste/lib/index.js:288:13)
    at /Users/User/f8app/node_modules/node-haste/lib/index.js:226:30
    at process._tickCallback (node.js:401:9)

How do I fix this?我该如何解决这个问题? Thank you.谢谢。

React-native version: react-native-cli: 1.0.0 react-native: 0.28.0反应原生版本:反应原生cli:1.0.0 反应原生:0.28.0

EDIT: This is incredibly confusing, because index.ios.js is in the root of my project.编辑:这非常令人困惑,因为 index.ios.js 位于我项目的根目录中。

I had similar problem and it took a while to narrow down the cause issue.我遇到了类似的问题,花了一段时间来缩小原因问题的范围。 React sometimes does not does automatically link sublibraries to iOS project. React 有时不会自动将子库链接到 iOS 项目。 Your library might require some of the additional RCT* dependencies, which are downloaded and are in node_modules/react-native folder.您的库可能需要一些额外的RCT*依赖项,这些依赖项已下载并位于 node_modules/react-native 文件夹中。 You will need to link it manually.您需要手动链接它。

For example I used CocoaPods for iOS dependency management and my react native looks like this:例如,我使用 CocoaPods 进行 iOS 依赖管理,我的 React Native 如下所示:

pod 'React', :path => '../../node_modules/react-native', :subspecs => [
   'Core',
    'RCTText',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTSettings',
    'RCTVibration',
    'RCTGeolocation',
    'RCTActionSheet',
    'RCTNetwork',
    'RCTWebSocket'
  ]

If you are using react-native link or manually linking in XCode , make sure to add these files into your Xcode project.如果您在XCode中使用react-native link或手动链接,请确保将这些文件添加到您的 Xcode 项目中。 More details in Facebook documentation Facebook 文档中的更多详细信息

  1. Delete node modules, podfile.lock and pods folder inside ios folder.删除 ios 文件夹中的节点模块、podfile.lock 和 pods 文件夹。
  2. Run yarn install in project directory.在项目目录中运行 yarn install。
  3. Run pod install inside ios folder.在 ios 文件夹中运行 pod install。

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

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