OneSignal / react-onesignal

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

The script has an unsupported MIME type ('text/html')[Bug]: #77

Closed KellsWorks closed 1 year ago

KellsWorks commented 1 year ago

What happened?

I was setting up react-onesignal on my vite react app (https://documentation.onesignal.com/docs/react-js-setup). l perfectly configured everything with the worker, accessible at http://localhost:3000/OneSignalSDKWorker.js. The issue is on production. l can't access the OneSignalSDKWorker.js. Does this work only in development or ? Because l have tried like alot

Steps to reproduce?

await OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' });
// do other stuff

What did you expect to happen?

l expect to find the OneSignalSDKWorker.js file after l deploy the app

Relevant log output

No response

KellsWorks commented 1 year ago

l found a work around with rollup.js

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react()],
  build: {
    rollupOptions: {
      input: {
        app: './index.html',
        'OneSignalSDKWorker': './OneSignalSDKWorker.js',
      },
      output: {
        entryFileNames: assetInfo => {
          return assetInfo.name === 'OneSignalSDKWorker' ? '[name].js' : 'assets/js/[name].js'
        }
      },
    },
  },
})