Skip to content

bug(@angular/pwa): ng add @angular/pwa fails to update angular.json and register service worker #32399

@kareemwezza

Description

@kareemwezza

Command

add

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

20

Description

After running ng add @angular/pwa, the application fails to register the service worker. Specifically, the browser attempts to fetch ngsw-worker.js but receives a 404 Not Found error. Investigation shows that the angular.json file was either not updated with the serviceWorker: true flag or the build process is not generating the required service worker files in the output directory.

The issue is resolved only after manually editing angular.json. This indicates the schematic is failing to write the necessary configuration to the workspace file even though it reports success.

Image

Expected Behavior

The ng add schematic should correctly configure angular.json so that ng build generates ngsw-worker.js and ngsw.json in the production output. The service worker should be successfully registered and visible in chrome://serviceworker-internals/.

Environment
Angular: 21.0.8
Angular CLI: 21.0.5
Node: 24.12.0
OS: darwin arm64

Minimal Reproduction

1. Run ng add @angular/pwa --project your-project-name.
2. Run a production build: ng build --configuration production.
3. Serve the dist/ folder using a static server (e.g., http-server).
4. Open the browser and check the Network Tab.
5. Observed Error: A request for /ngsw-worker.js fails with a 404 error. 
Image

Exception or Error

Always getting Network error 404 while trying to request ngsw-worker.js file.

Your Environment

Angular CLI       : 21.0.5
Angular           : 21.0.8
Node.js           : 24.12.0
Package Manager   : pnpm 10.28.1
Operating System  : darwin arm64

Anything else relevant?

Usin Pnpm Package menager
Issue happens woth http-server and default ng server

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions