TypeError: Cannot read properties of undefined (reading 'messaging')

Viewed 341

I've been struggling couple of days ago solving this problem but I failed I tried everything and none worked for me this is the issue TypeError: Cannot read properties of undefined (reading 'messaging') at new firebase_messaging_web.FirebaseMessagingWeb.new (http://localhost:62947/packages/firebase_messaging_web/firebase_messaging_web.dart.lib.js:167:41)

it happened when i tried to add web sdk to my flutter project this is the full log `Launching lib\main.dart on Edge in debug mode... Waiting for connection from debug service on Edge... This app is linked to the debug service: ws://127.0.0.1:63030/JTHIJVOzDxA=/ws Debug service listening on ws://127.0.0.1:63030/JTHIJVOzDxA=/ws

Running with unsound null safety For more information see https://dart.dev/null-safety/unsound-null-safety Debug service listening on ws://127.0.0.1:63030/JTHIJVOzDxA=/ws TypeError: Cannot read properties of undefined (reading 'messaging') at new firebase_messaging_web.FirebaseMessagingWeb.new (http://localhost:62947/packages/firebase_messaging_web/firebase_messaging_web.dart.lib.js:167:41) at Function.registerWith (http://localhost:62947/packages/firebase_messaging_web/firebase_messaging_web.dart.lib.js:53:73) at Object.registerPlugins (http://localhost:62947/packages/elite_auction/generated_plugin_registrant.dart.lib.js:24:49) at main (http://localhost:62947/web_entrypoint.dart.lib.js:34:35) at main.next () at runBody (http://localhost:62947/dart_sdk.js:43013:34) at Object._async [as async] (http://localhost:62947/dart_sdk.js:43044:7) at main$ (http://localhost:62947/web_entrypoint.dart.lib.js:33:18) at http://localhost:62947/main_module.bootstrap.js:19:10 at Array.forEach () at window.$dartRunMain (http://localhost:62947/main_module.bootstrap.js:18:32) at :1:8 at Object.runMain (http://localhost:62947/dwds/src/injected/client.js:8707:21) at http://localhost:62947/dwds/src/injected/client.js:23873:19 at _wrapJsFunctionForAsync_closure.$protected (http://localhost:62947/dwds/src/injected/client.js:3487:15) at _wrapJsFunctionForAsync_closure.call$2 (http://localhost:62947/dwds/src/injected/client.js:11518:12) at Object._asyncStartSync (http://localhost:62947/dwds/src/injected/client.js:3451:20) at main__closure3.$call$body$main__closure (http://localhost:62947/dwds/src/injected/client.js:23885:16) at main__closure3.call$1 (http://localhost:62947/dwds/src/injected/client.js:23812:19) at StaticClosure._rootRunUnary (http://localhost:62947/dwds/src/injected/client.js:3849:18) at _CustomZone.runUnary$2$2 (http://localhost:62947/dwds/src/injected/client.js:12877:39) at _CustomZone.runUnaryGuarded$1$2 (http://localhost:62947/dwds/src/injected/client.js:12813:14) at _ForwardingStreamSubscription._sendData$1 (http://localhost:62947/dwds/src/injected/client.js:12403:19) at _ForwardingStreamSubscription._add$1 (http://localhost:62947/dwds/src/injected/client.js:12349:15) at _ForwardingStreamSubscription._add$1 (http://localhost:62947/dwds/src/injected/client.js:12682:12) at _MapStream._handleData$2 (http://localhost:62947/dwds/src/injected/client.js:12743:12) at _ForwardingStreamSubscription._handleData$1 (http://localhost:62947/dwds/src/injected/client.js:12708:20) at tear_off. (http://localhost:62947/dwds/src/injected/client.js:1392:45) at StaticClosure._rootRunUnary (http://localhost:62947/dwds/src/injected/client.js:3849:18) at _CustomZone.runUnary$2$2 (http://localhost:62947/dwds/src/injected/client.js:12877:39) at _CustomZone.runUnaryGuarded$1$2 (http://localhost:62947/dwds/src/injected/client.js:12813:14) at _ControllerSubscription._sendData$1 (http://localhost:62947/dwds/src/injected/client.js:12403:19) at _ControllerSubscription._add$1 (http://localhost:62947/dwds/src/injected/client.js:12349:15) at _SyncStreamController._sendData$1 (http://localhost:62947/dwds/src/injected/client.js:12197:32) at _SyncStreamController.add$1 (http://localhost:62947/dwds/src/injected/client.js:12078:15) at tear_off. (http://localhost:62947/dwds/src/injected/client.js:1450:48) at StaticClosure._rootRunUnary (http://localhost:62947/dwds/src/injected/client.js:3849:18) at _CustomZone.runUnary$2$2 (http://localhost:62947/dwds/src/injected/client.js:12877:39) at _CustomZone.runUnaryGuarded$1$2 (http://localhost:62947/dwds/src/injected/client.js:12813:14) at _ControllerSubscription._sendData$1 (http://localhost:62947/dwds/src/injected/client.js:12403:19) at _ControllerSubscription._add$1 (http://localhost:62947/dwds/src/injected/client.js:12349:15) at _SyncStreamController._sendData$1 (http://localhost:62947/dwds/src/injected/client.js:12197:32) at _SyncStreamController.add$1 (http://localhost:62947/dwds/src/injected/client.js:12078:15) at _GuaranteeSink.add$1 (http://localhost:62947/dwds/src/injected/client.js:23352:25) at HtmlWebSocketChannel_closure1.call$1 (http://localhost:62947/dwds/src/injected/client.js:23637:149) at _EventStreamSubscription_closure.call$1 (http://localhost:62947/dwds/src/injected/client.js:17865:26) at StaticClosure._rootRunUnary (http://localhost:62947/dwds/src/injected/client.js:3855:16) at _CustomZone.runUnary$2$2 (http://localhost:62947/dwds/src/injected/client.js:12877:39) at _CustomZone.runUnaryGuarded$1$2 (http://localhost:62947/dwds/src/injected/client.js:12813:14) at _CustomZone_bindUnaryCallbackGuarded_closure.call$1 (http://localhost:62947/dwds/src/injected/client.js:13014:25) at invokeClosure (http://localhost:62947/dwds/src/injected/client.js:1281:26) at WebSocket. (http://localhost:62947/dwds/src/injected/client.js:1300:18) `

Blockquote

and this is my web/index file

I Deleted the firebaseConfig values so please don't mention it

<!DOCTYPE html>
<html>
<head>
  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    For more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
  -->
  <base href="/">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- iOS meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="elite_auction">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <title>elite_auction</title>
  <link rel="manifest" href="manifest.json">
</head>
<body>
  <!-- This script installs service_worker.js to provide PWA functionality to
       application. For more information, see:
       https://developers.google.com/web/fundamentals/primers/service-workers -->
  <script>
    var serviceWorkerVersion = null;
    var scriptLoaded = false;
    function loadMainDartJs() {
      if (scriptLoaded) {
        return;
      }
      scriptLoaded = true;
      var scriptTag = document.createElement('script');
      scriptTag.src = 'main.dart.js';
      scriptTag.type = 'application/javascript';
      document.body.append(scriptTag);
    }

     if ('serviceWorker' in navigator) {
  window.addEventListener('load', function () {
    navigator.serviceWorker.register("/firebase-messaging-sw.js");
        navigator.serviceWorker.register(serviceWorkerUrl)
          .then((reg) => {
            function waitForActivation(serviceWorker) {
              serviceWorker.addEventListener('statechange', () => {
                if (serviceWorker.state == 'activated') {
                  console.log('Installed new service worker.');
                  loadMainDartJs();
                }
              });
            }
            if (!reg.active && (reg.installing || reg.waiting)) {
              // No active web worker and we have installed or are installing
              // one for the first time. Simply wait for it to activate.
              waitForActivation(reg.installing ?? reg.waiting);
            } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
              // When the app updates the serviceWorkerVersion changes, so we
              // need to ask the service worker to update.
              console.log('New service worker available.');
              reg.update();
              waitForActivation(reg.installing);
            } else {
              // Existing service worker is still good.
              console.log('Loading app from service worker.');
              loadMainDartJs();
            }
          });

        // If service worker doesn't succeed in a reasonable amount of time,
        // fallback to plaint <script> tag.
        setTimeout(() => {
          if (!scriptLoaded) {
            console.warn(
              'Failed to load app from service worker. Falling back to plain <script> tag.',
            );
            loadMainDartJs();
          }
        }, 4000);
      });
    } else {
      // Service workers not supported. Just drop the <script> tag.
      loadMainDartJs();
    }
  </script>
  <script>
    if ('serviceWorker' in navigator) {
      window.addEventListener('load', function () {
        navigator.serviceWorker.register('flutter_service_worker.js');
      });
    }
  </script>
  <script type="module">
  // Import the functions you need from the SDKs you need
  import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.11/firebase-app.js";
  import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.11/firebase-auth.js";
  import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.11/firebase-messaging.js";

  // Your web app's Firebase configuration
  // For Firebase JS SDK v7.20.0 and later, measurementId is optional
  const firebaseConfig = {
    apiKey: "",
    authDomain: "",
    projectId: "",
    storageBucket: "",
    messagingSenderId: "",
    appId: "1::web:",
    measurementId: ""
  };

  // Initialize Firebase
  const app = initializeApp(firebaseConfig);
  const messaging = getMessaging(app);
  const auth = getAuth(app);
</script>
 <script src="main.dart.js" type="application/javascript"></script>
</body>

</html>

Any Ideas to solve this problem ?

0 Answers
Related