Angular-cli: Service Worker files ngsw.json and ngsw-worker.js not getting bundled

Created on 20 Oct 2018  路  7Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions


Angular CLI: 7.0.2
Node: 8.11.2
OS: linux x64
Angular: 6.0.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

Package Version

@angular-devkit/architect 0.6.8
@angular-devkit/build-angular 0.6.8
@angular-devkit/build-optimizer 0.6.8
@angular-devkit/core 0.6.8
@angular-devkit/schematics 7.0.2
@angular/cdk 6.3.2
@angular/cli 6.2.6
@angular/material 6.3.2
@angular/pwa 0.10.2
@ngtools/webpack 6.0.8
@schematics/angular 7.0.2
@schematics/update 0.8.6
rxjs 6.2.1
typescript 2.7.2
webpack 4.8.3

Repro steps


ng build --prod

The log given by the failure


missing ngsw.json and ngsw-worker.js in dist

Desired functionality


must create appropriate ngsw.json and ngsw-worker.js in dist

Mention any other details that might be useful


The service worker files are added in dist folder for the same private repo if Angular CLI : 6.2.6 is used

repro steps

Most helpful comment

I had the same issue, but I forgot to add "serviceWorker: true" in my angular.json for the specific build. (It was added for production configuration automatically, but I needed to add it to my other configurations.)

All 7 comments

Hi, from the logs above, it shows that you are using Angular CLI version6.2.6 and not 7.0.2 as initially stated.

Also, can you please setup a minimal repro please?

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

This might be related to your directory structure so its really important to get an accurate repro to diagnose this.

I tried creating repro-app as per your instruction and ngsw.json, ngsw-worker.js are getting populated when creating a production build (ng build --prod)
In the prevate repo, all the angular dependencies where using 6.0.7 and have moved them manually to 7.0.0 (@angular/animations, @angular/core, @angular/forms ...). After this, things are working properly.

Thanks for your help.

I got the same issue here, updating angular PWA module and not working as expected anymore. I have angular CLI 7, and Angular 7 everywhere. What can be the issue ?

UPDATE: If anybody come up with the same issue, for me it came from my version of

@angular-devkit/build-angular, which was at 0.8 instead of 0.10:

"@angular-devkit/build-angular": "~0.10.0",

And it solved my issue, generating the missing files.

I had the same issue, but I forgot to add "serviceWorker: true" in my angular.json for the specific build. (It was added for production configuration automatically, but I needed to add it to my other configurations.)

@JudahGabriel - this helped me, thank you sir,

Your build package is not up to date. Update it

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

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings