需要未知模块的React-native错误“反应”
当我使用Xcode运行反应本机应用程序,并在应用程序开始加载后,我看到这个错误:
"Requiring unknown module "react". If you are sure the module is there, try restarting the packager."
我的package.json的内容是:
{ "name": "the_golf_mentor", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start" }, "dependencies": { "react-native": "^0.21.0", "react-native-button": "^1.4.2", "react-native-cookies": "^0.0.5", "react-native-db-models": "^0.1.3", "react-native-navbar": "^1.2.1", "react-native-side-menu": "^0.18.0", "tcomb-form-native": "^0.3.3" } }
我已经尝试重新启动包pipe理器,并且还删除了node_module文件夹并完成了全新的npm install
。 我该如何解决这个问题?
启用热重新加载后,我有这个,然后降级我的反应版本,以支持我正在使用的图书馆。
模拟器>重置内容和设置
得到它再次运行。
在React Native中React
生活在react-native
模块而不是react
(对于React JS)。 在这种情况下,通过以下方式导入React
和其他React Native模块:
import React, { Component, View, Text, // other React Native modules } from 'react-native';
你应该要求React
从react-native
生的项目中反应,而不是从react
。
var React = require('react-native');
事实certificate,这个错误信息是我在debugging器中收到的临时信息。 当我在debugging器中连续按几次时,在模拟器窗口中收到一条消息,表明我没有正确注册应用程序,即我的AppRegistry.registerComponent
调用无效。
我怀疑这是unknown module 'react'
错误消息的不寻常的原因。 在许多情况下, neciu's
答案可能更有用,所以我也赞成这个答案。