【发布时间】:2015-09-28 02:33:43
【问题描述】:
我是 React Native 的新手,想在我正在玩的 React Native 应用程序中使用节点模块。
我想添加的节点模块是这样的: https://www.npmjs.com/package/swisseph
所以我进入项目文件夹并运行npm install swisseph
在应用程序源代码中我添加了这个:
var swisseph = require ('swisseph');
我运行了这个项目,我得到了这个错误:
Invariant Violation: Application AwesomeProject has not been registered.
This is either due to a require() error during initialisation or failure to call AppRegistry.registerComponent.
如何在 React Native 中使用节点模块?
index.io.js 文件有以下代码:
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var swisseph = require ('swisseph');
var {
AppRegistry,
StyleSheet,
Text,
View,
} = React;
var AwesomeProject = React.createClass({
render: function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
【问题讨论】:
-
你的
index.ios.js是什么样的? -
您好,我在上面的 index.ios.js 中添加了代码...谢谢...
-
它说 AwesomeProject not swisseph 所以这个特定的错误可能不是由新添加的模块引起的。尝试此处提供的解决方案 stackoverflow.com/questions/29287987/… 当我遇到
has not been registered错误时,这对我有用。
标签: javascript node.js reactjs react-native node-modules