OneSignal / react-onesignal

React OneSignal Module: Make it easy to integrate OneSignal with your React App!
Other
73 stars 26 forks source link

Unable to set up oneSignal with React Native Web #62

Closed itsramiel closed 2 years ago

itsramiel commented 2 years ago

I am trying to build a cross platform app ios/android/web using react native. I will be using react native web to build for web. I have followed the setup guide from the documentation, but I was not successful. I have added the following to my root App component:

useEffect(() => {
        console.log("inisde use effect");
        OneSignalReact.init({ appId: "4ffe42fb-8990-411d-8c23-34f9f393b149" })
            .then(() => console.log("one signal initted"))
            .catch((err) => console.log(err));

        console.log("after use effect");
    }, []);

I have the service worker file "OneSignalSDKWorker.js" in the root of my project, and setup the application on OneSignal for local testing and ran the local server for react native web.

I received the popup asking for the subscription to notification, but when I press subscribe, the service worker fail to load and I get an error.

The script has an unsupported MIME type ('text/html')
[Service Worker Installation] Installing service worker failed SecurityError: Failed to register a ServiceWorker for scope ('http://localhost:19006/') with script ('http://localhost:19006/OneSignalSDKWorker.js?appId=4ffe42fb-8990-411d-8c23-34f9f393b149?sdkVersion=151513'): The script has an unsupported MIME type ('text/html').

Is OneSignal supposed to work with React Native web or what can i do?

rgomezp commented 2 years ago

Howdy, You should be able to visit http://localhost:19006/OneSignalSDKWorker.js in the browser and it load fine. Try doing that. Perhpas you are not hosting it correctly.

rgomezp commented 2 years ago

Closing due to inactivity