Skip to content

Compatibility with Expo apps #8

Description

@bboydflo

hi, thanks for this package. I am trying to use it in an expo app. and I got this error: TypeError: null is not an object (evaluating 'FPStaticServer.start'

Any idea what I am doing wrong? Here is my code:

import { StatusBar } from 'expo-status-bar';
import { StyleSheet, SafeAreaView } from "react-native";
import { WebView } from 'react-native-webview';
import StaticServer from "@dr.pogodin/react-native-static-server";
import { useEffect, useRef, useState } from 'react';

export default function App() {
  // const [uri] = useState("https://google.com");
  const server = useRef(new StaticServer(5555, "./assets", { localOnly: true, keepAlive: true })).current;
  const [uri] = useState(`http://localhost:${server.port}`);

  useEffect(() => {
    server.start().then((url) => {
      console.log("Serving at URL", url);
    });

    () => {
      // Stop the server
      server.stop();
    }
  }, []);

  return (
    <SafeAreaView style={styles.container}>
      <WebView
        style={styles.container}
        originWhitelist={["*"]}
        source={{ uri }}
        cacheEnabled={true}
        cacheMode={"LOAD_CACHE_ONLY"}
        limitsNavigationsToAppBoundDomains={true}
      />
      <StatusBar style="auto" />
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

Here is some output in my logs:

TypeError: null is not an object (evaluating 'FPStaticServer.start')

This error is located at:
    in App (created by ExpoRoot)
    in ExpoRoot
    in RCTView (created by View)
    in View (created by AppContainer)
    in DevAppContainer (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in main(RootComponent)
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException
at node_modules/react-native/Libraries/Core/ReactFiberErrorDialog.js:52:4 in showErrorDialog
at node_modules/react-native/Libraries/ReactNative/renderApplication.js:80:4 in renderApplication
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:119:25 in runnables.appKey.run
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:213:4 in runApplication

TypeError: null is not an object (evaluating 'FPStaticServer.start')

This error is located at:
    in App (created by ExpoRoot)
    in ExpoRoot
    in RCTView (created by View)
    in View (created by AppContainer)
    in DevAppContainer (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in main(RootComponent)
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/expo/build/errors/ExpoErrorManager.js:25:19 in errorHandler
at node_modules/expo/build/errors/ExpoErrorManager.js:30:24 in <anonymous>
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0

And below are some expo logs:

IMG_C1EF1CFC4289-1

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExpoExpo - Isn't officially supported yet.On HoldCannot be resolved at the moment.P4No action needed at this time.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions