Angular-cli: Service worker, angular cli 6.0.0-beta6 build --prod doesn't produce ngsw-worker.js and ngsw-config.json

Created on 22 Mar 2018  路  13Comments  路  Source: angular/angular-cli

Versions

Angular CLI: 6.0.0-beta.6
Node: 9.8.0
OS: darwin x64
Angular: 5.2.9
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker

@angular/cli: 6.0.0-beta.6
@angular-devkit/architect: 0.0.7
@angular-devkit/build-optimizer: 0.4.6
@angular-devkit/build-webpack: 0.0.7
@angular-devkit/core: 0.4.6
@angular-devkit/schematics: 0.4.6
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 6.0.0-beta.6
@schematics/angular: 0.4.6
@schematics/package-update: 0.4.6
typescript: 2.5.3
webpack: 4.1.1

Repro steps

  • Step 1
    run ng new swtest --service-worker
  • Step 2
    run ng build --prod in project directory

Observed behavior

no ngsw-worker.js and ngsw-config.json found in ./dist/

Desired behavior


ngsw-worker.js and ngsw-config.json should be found in ./dist/

Mention any other details that might be useful (optional)

It works fine in Angular 5

triage #1

Most helpful comment

The --service-worker is no longer available on the ng new command. The ability to add service worker to a project will be done via ng add @angular/pwa --project [project name].

With that being said, the reason you're not seeing service worker files in your dist directory is likely due to the fact that service worker is not configured for your project.

All 13 comments

It works in angular 6 beta 3, but failed starting from beta 4.

Same issue on beta 5

Still failing on 6.0.0-rc.0

Yes this is a bug with how we look for the ngsw-worker.js file. Will fix.

The --service-worker is no longer available on the ng new command. The ability to add service worker to a project will be done via ng add @angular/pwa --project [project name].

With that being said, the reason you're not seeing service worker files in your dist directory is likely due to the fact that service worker is not configured for your project.

Currently the service worker functionality is bundled in with ng add @angular/pwa, adding just service worker alone could be done via something like ng add @angular/service-worker is being considered for v6.1

@Brocco I hope you will have a look at https://github.com/angular/devkit/issues/686 before the release - because the second part of @angular/pwa (Web App Manifest) is not complete

As @Brocco mentioned above, if you get

Data path "" should have required property 'project'.

Don't forget to use:

ng add @angular/pwa --project [project name]

It's already possible to just add service worker alone (same as old ng new helloworld --service-worker) with:
ng g service-worker

Btw, --project is not required anymore for ng add @angular/pwa.

A lot of issues were fixed about SW/PWA, so last RC is required.

Note to anyone upgrading from 5.x projects with service workers. You have to run ng add @angular/pwa again to get this to work. ng update eats it from my testing.

ng build --prod works, but ng serve --prod does not

The original issue was against a beta version of 6.0 and should no longer be a problem with the latest version of the Angular CLI. If anyone is still encountering the issue, please open a new issue with the project's current version information.

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