After Angular 6 update, ng build --prod yields "Error: Expected to find an ngsw-config.json configuration file"
Asked Answered
F

5

19

The update went fine, but now when I build, I get the following error.

Error: Expected to find an ngsw-config.json configuration file in the /Users/nathanielmay/Code/firebaseTest folder. Either provide one or disable Service Worker in your angular.json configuration file.

I looked in my angular.json and found that on this line:

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

Property ngswConfigPath is not allowed.

I can't find an api for the new angular.json, but it seems as if I need to specify the path in a different way.

ng update @angular/pwa didn't work either.

How can I resolve this error?

Faustina answered 6/5, 2018 at 4:16 Comment(0)
F
18

I'm not sure how "ngswConfigPath": "/src/ngsw-config.json", was added, but I removed it and it built fine.

Next issue I faced was that ngsw-config.json has been moved out of src and to the project root during the upgrade. I had to copy my updates into the root ngsw-config.json for the service worker to register properly.

Faustina answered 6/5, 2018 at 5:40 Comment(0)
E
38

Please make sure to build your app in root folder. I had the same issue and building from the root folder solved my issue.

Eulogia answered 16/1, 2020 at 16:35 Comment(1)
my project was angular multi project, and instead of being in root folder for build command I was in "project" folder, and after going to root it worked with no problemNyctalopia
F
18

I'm not sure how "ngswConfigPath": "/src/ngsw-config.json", was added, but I removed it and it built fine.

Next issue I faced was that ngsw-config.json has been moved out of src and to the project root during the upgrade. I had to copy my updates into the root ngsw-config.json for the service worker to register properly.

Faustina answered 6/5, 2018 at 5:40 Comment(0)
M
6

For my case issue was connected with / sign added at the front of the path, so instead of "ngswConfigPath": "/src/ngsw-config.json" I've used "ngswConfigPath": "src/ngsw-config.json" and issue fixed.

Matisse answered 14/5, 2018 at 19:35 Comment(2)
I had the same issue and removing the trailing / fixed it.Bemire
I had the same issue after upgrading from ng5 to ng6. Removing the trailing / fixed it for me too.Diatom
R
3

Actually the file ngsw-config.json is generated but is on a different location. First disable Service Worker in your angular.json/angular-cli.json configuration file. Then run ng build --prod on your terminal. It should run without errors.

Then enable the service worker in your angular.json/angular-cli.json and run the ng build --prod command again in your terminal.

Reduction answered 14/5, 2018 at 10:41 Comment(2)
This worked for me using @nrwl/nx. Remove serviceWorker: true from angular.json, use ng build myapp --prod, revert angular.json, and build again. Presto.Yale
@Yale I use @nrwl/nx too, but your solution does not work for me.Styria
S
0

You can use this link of the official angular website for PWA (service worker).

Anyway, you can run this command to automatically configure PWA for your application.

ng add  @angular/pwa --project *your-project-name*

Or, if you looking for a specific version of PWA, then you can run this (the word "version" in the command below refers to the version of PWA. for example: @13.2.0):

ng add  @angular/pwa@verion --project *your-project-name*

By running this command the following changes will be done:

  1. The manifest.webmanifest will be created on src folder
  2. Also, the ngsw-config.json will be created on root directory of the
  3. And, some minor changes (service worker configurations) will be done on angular.json file
Styria answered 11/4, 2022 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.