nuxt-community / onesignal-module

OneSignal for Nuxt 2
MIT License
74 stars 8 forks source link

OneSignal Safari - JS error when in production mode and using internally supplied OneSignal SDK #7

Closed obj63mc closed 4 years ago

obj63mc commented 6 years ago

Currently in the latest version of safari, nuxt and this pwa module, when I am using Workbox and Onesignal, I am getting the following error when running the site in production mode with - nuxt build && nuxt start

    Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'p.pushManager.getSubscription')

My setup for the PWA Module with OneSignal and Webpack is the following -

    modules:[
        '@nuxtjs/onesignal',
        '@nuxtjs/pwa',
        '@nuxtjs/browserconfig',
        '@nuxtjs/font-awesome',
        '@nuxtjs/redirect-module',
        'cookie-universal-nuxt',
        ['nuxt-sass-resources-loader', '@/assets/scss/layout.scss'],
    ],
    meta:{
        nativeUI:true,
        mobileAppIOS:false,
        favicon:true,
        ogHost: process.env.FACEBOOKHOST,
        ogImage: {
          path: '/fb-share.jpg',
          width:'1200',
          height:'630',
          type:'image/jpg'
        },
        twitterCard: 'summary_large_image',
        twitterCreator: '@',
        twitterSite: '@'
    },
    oneSignal: {
        init: {
          appId: process.env.ONESIGNALKEY,
          allowLocalhostAsSecureOrigin: true,
          welcomeNotification: {
              disable: true
          },
          autoRegister: false,
          promptOptions: {                
              actionMessage: "...",               
              acceptButtonText: "...",                
              cancelButtonText: "..."
          }
        }
    }
    build: {
        vendor:[
          'socket.io-client',
          'babel-polyfill',
          'vee-validate',
          '@xkeshi/vue-countdown',
          'vue-the-mask',
                'vue-flickity',
          'moment-timezone',
          'lottie-web',
          '~/static/svg-data/bell.json',
          '~/static/svg-data/bottle.json',
          '~/static/svg-data/building.json',
          '~/static/svg-data/clock.json',
        ],
        babel:{
          presets({server}) {
            return [
              ['vue-app',
                {
                  useBuiltIns: true,
                  targets: server ? { node: 'current' } : {ie: 11, uglify: true}
                }
              ]
            ];
          }
        },
        postcss: [
          require('postcss-fixie')(),
          require('postcss-utilities')(),
          require('postcss-aspect-ratio')(),
        ],
        extractCSS: {
          allChunks: true
        },
        extend (config, { isDev, isClient }) {
          if (isDev && isClient) {
            config.module.rules.push({
              enforce: 'pre',
              test: /\.(js|vue)$/,
              loader: 'eslint-loader',
              exclude: /(node_modules)/
            })
          }
        }
    },

Any idea how to resolve this error? If I set OneSignal to use their CDN SDK I don't get an error but then I am unable to test on localhost and it doesn't use my init configs.

Example of that config is -

    oneSignal: {
        cdn: true,
        OneSignalSDK: 'https://cdn.onesignal.com/sdks/OneSignalSDK.js',
        init: {
          appId: process.env.ONESIGNALKEY,
          allowLocalhostAsSecureOrigin: true,
          welcomeNotification: {
              disable: true
          },
          autoRegister: false,
          promptOptions: {                
              actionMessage: "...",               
              acceptButtonText: "...",                
              cancelButtonText: "..."
          }
        }
    }
This question is available on Nuxt community (#c62)
ghost commented 6 years ago

This issue as been imported as question since it does not respect pwa-module issue template. Only bug reports and feature requests stays open to reduce maintainers workload. If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically. Your question is available at https://cmty.app/nuxt/pwa-module/issues/c62.

obj63mc commented 6 years ago

When looking at this, seems it was resolved with an SDK update in July - https://github.com/OneSignal/OneSignal-Website-SDK/issues/380

Also looks like the latest versions of OneSignal want you to create a seperate app for testing localhost directly so that can be ignored.

pi0 commented 5 years ago

@obj63mc with 3.0.0 onesignal will use CDN by default. Also, local version updated. Thanks for the report.