我将我的应用程序与Expo分离,安装并链接了react native静态服务器模块。我在应用程序中添加了这段代码。js文件,就在组件定义之前,查看其工作原理:
import StaticServer from 'react-native-static-server';
const server = new StaticServer( 8080, { localOnly: false, keepAlive : true } );
server.start( ).then( ( url ) => {
console.log( "Serving at URL", url );
} );
现在,我在调用start()方法时出现了以下错误:
TypeError: undefined is not an object (evaluating 'this.staticServer.start')
应用程序不断崩溃并重新启动。到目前为止,我只在Android上进行了测试。有人知道我做错了什么吗?我在github上没有看到任何与此相关的问题。
Android Studio中我的应用程序的Logcat显示以下内容:
D/ReactNative: ReactInstanceManager.createReactContextInBackground()
D/ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
W/unknown:ReactNative: Tried to enqueue runnable on already finished thread: 'native_modules... dropping Runnable.
W/MessageQueue: Handler (com.facebook.react.bridge.queue.MessageQueueThreadHandler) {14699d1} sending message to a Handler on a dead thread
java.lang.IllegalStateException: Handler (com.facebook.react.bridge.queue.MessageQueueThreadHandler) {14699d1} sending message to a Handler on a dead thread
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:545)
at android.os.Handler.enqueueMessage(Handler.java:662)
at android.os.Handler.sendMessageAtTime(Handler.java:631)
at android.os.Handler.sendMessageDelayed(Handler.java:601)
at android.os.Handler.post(Handler.java:357)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl.runOnQueue(MessageQueueThreadImpl.java:61)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:164)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
at java.lang.Thread.run(Thread.java:764)