bug(@angular/pwa): ng add @angular/pwa fails to update angular.json and register service worker
Command
add
Is this a regression?
- [x] 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.
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.
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
Do you have a production configuration? The service worker options are only added in the production configuration.
The app has 3 build configurations 'dev', 'tst' and 'liv'. Our Dev team moved from 'production' to 'liv' naming.
In this case we should issue a warning since the schematic is looking for a production configuration.
Can't agree more, Thanks for your support.
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.