Uncaught SyntaxError: Cannot use import statement outside a module in Angular & Firebase

Viewed 925

I got this error in Angular when try to connect firebase push notification setting. enter image description here

import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.1.0/firebase-app.js';
import { getMessaging, isSupported, onBackgroundMessage } from 'https://www.gstatic.com/firebasejs/9.1.0/firebase-messaging-sw.js';
    
    // Initialize the Firebase app in the service worker by passing in the
    // messagingSenderId.
    
    const firebaseApp = initializeApp({
      apiKey: "",
      authDomain: "",
      projectId: "",
      storageBucket: "",
      messagingSenderId: "",
      appId: "",
      measurementId: ""
    });
    
    // Retrieve an instance of Firebase Messaging so that it can handle background
    // messages.
    isSupported().then(isSupported => {
    
      if (isSupported) {
    
        const messaging = getMessaging(app);
    
        onBackgroundMessage(messaging, ({ notification: { title, body, image } }) => {
          self.registration.showNotification(title, { body, icon: image || '/assets/icons/icon-72x72.png' });
        });
    
      }
    
    });
1 Answers
Related