我按照这些规范开始了新的Angular 8项目:
Angular CLI: 8.0.4
Node: 10.16.0
OS: darwin x64
Angular: 8.0.2
角度PWA:
ng add @angular/pwa
package.json
"dependencies": {
"@angular/animations": "~8.0.1",
"@angular/common": "~8.0.1",
"@angular/compiler": "~8.0.1",
"@angular/core": "~8.0.1",
"@angular/forms": "~8.0.1",
"@angular/platform-browser": "~8.0.1",
"@angular/platform-browser-dynamic": "~8.0.1",
"@angular/pwa": "^0.800.4",
"@angular/router": "~8.0.1",
"@angular/service-worker": "~8.0.1",
"rxjs": "~6.4.0",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
启动时控制台出现2个错误。我该如何解决?
获取脚本时收到错误的HTTP响应代码(404)。 service-worker.js.pre-build-optimizer.js:451
服务人员 注册失败,原因:TypeError:无法注册 ServiceWorker:在以下情况下收到错误的HTTP响应代码(404) 获取脚本。
答案 0 :(得分:1)
如果您尝试使用CLI在本地进行测试,则服务工作者将抛出此错误。您需要测试以下these instructions。
此外,如果不在本地主机上,浏览器会通过不安全的连接(http或https)拒绝服务工作者,请参见here。