Firebase Cloud Messaging 在 angular 10 中无法在生产模式下运行

Firebase Cloud Messaging not working on production mode in angular 10

错误:

Messaging: We are unable to register the default service worker. ServiceWorker script at https://xxxxxx/firebase-messaging-sw.js for scope https://xxxxxxxx/firebase-cloud-messaging-push-scope encountered an error during installation. (messaging/failed-service-worker-registration).

Firebase 在本地主机上运行良好,但当我在服务器上上传构建时,开始显示上述错误。

目录结构:

src
   app
   assets
   environments
   favicon.io
   firebase-messaging-sw.js
   index.html
   main.ts
   manifest.json
   polyfills.ts
   styles.scss
   test.ts

经过大量的搜索和尝试,我发现我错过了在资产(页面-angular.json)中注册 firebase-messaging-sw.js。这解决了我的问题。