Firebase 部署 - Flutter Web - 未捕获类型错误:无法读取未定义的属性'isSupported'/无法为作用域注册 ServiceWorker



My Flutter web应用程序在部署到firebase后提供了2条错误消息。错误消息在部署之前没有出现。我找不到根本原因。

main.dart.js:39105 Uncaught TypeError: Cannot read property 'isSupported' of undefined
at aaA.a2R (main.dart.js:47197)
at Object.aP_ (main.dart.js:22954)
at main.dart.js:10007
at aGN.a (main.dart.js:5110)
at aGN.$2 (main.dart.js:38004)
at Object.H (main.dart.js:5096)
at aHW (main.dart.js:10032)
at main.dart.js:97159
at main.dart.js:97153
at dartProgram (main.dart.js:97156)
(index):1 Uncaught (in promise) TypeError: Failed to register a ServiceWorker for scope ('https://*****.web.app/') with script ('https://*****.web.app/flutter_service_worker.js'): A bad HTTP response code (404) was received when fetching the script.

该应用程序在web渲染下运行时正常工作,没有任何问题。

我的猜测来自firebase JavaScript文件确实提供了存储在firebase中的错误消息。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="***">
<!-- 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="*/*** Store">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<meta name="google-signin-client_id" content="234259997949-29sp95o3qnl5s9ofdl0ib2eb7mho1avm.apps.googleusercontent.com">
<!-- Favicon -->
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
<title>Eletanco Store</title>
<link rel="manifest" href="manifest.json">
</head>
<body>

<!-- The core Firebase JS SDK is always required and must be listed first --> 
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-analytics.js"></script>

<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
****
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
<script src="main.dart.js" type="application/javascript"></script>

<!-- 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>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<!-- include only the Firebase features as you need -->
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-functions.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-messaging.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-storage.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-remote-config.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-performance.js"></script>
<!-- 
initialize the SDK after all desired features are loaded, set useEmulator to false
to avoid connecting the SDK to running emulators.
-->

</body>
</html>

我找到了解决方案

  1. 我删除了以下

    if(导航器中的"serviceWorker"({window.addEventListener('load',function(({navigator.serviceWorker.register('fuster_service_worker.js'(;});}
  2. 我升级了所有的javascript链接,并再次启动了FirebaseInitiates。

最新更新