当我运行react-native run-android
时,我的模拟器显示此错误:
我想运行react-native-static-server以使用Webview在我的应用程序中离线显示react-vr导览。
这是我已构建项目的命令:
react-native init serverApp
cd serverApp
npm install react-native-static-server --save
react-native run-android
我已使用以下代码编辑App.js:
import StaticServer from 'react-native-static-server';
let server = new StaticServer(8080);
// Start the server
server.start().then((url) => {
console.log("Serving at URL", url);
});
server.stop();
App.js:
import React, {Component} from 'react';
import {StyleSheet, Text, View} from 'react-native';
import StaticServer from 'react-native-static-server';
let server = new StaticServer(8080);
// Start the server
server.start().then((url) => {
console.log("Serving at URL", url);
});
server.stop();
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>To get started, edit App.js</Text>
</View>
);
}
}
const 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,
},
});
问题:
我如何使用react-native-static-server运行本地服务器?
或
我如何解决此错误?