Angular ServiceWorkers + MIME type error

半腔热情 提交于 2019-12-04 01:39:22

This is probably caused by a missing ngsw-worker.js file.

Likely you are using HTML5 pushState style URLs, and you have configured your web server to return your index page (typically index.html) for any file or folder that does not physically exist on the server. If ngsw-worker.js does not physically exist, the web server will redirect a request to ngsw-worker.js to index.html (hence the MIME type "text/html").

The ngsw-worker.js file is typically copied to your dist folder when you run

ng build --prod

After trying a lot of different things with Angular8 I finally upgraded angular-devkit from 0.800.2 to 0.803.2

npm install @angular-devkit/build-angular@latest

Then I got an error:

Error: Expected to find an ngsw-config.json configuration file in the [PROJECT] folder. Either provide one or disable Service Worker in your angular.json configuration file.

I fixed this by changing

"ngswConfigPath": "ngsw-config.json" to "ngswConfigPath": "src/ngsw-config.json"

Then it finally worked.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!