Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 852
Nate May Avatar asked May 06 '18 04:05

Nate May


4 Answers

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

like image 108
Chamila Maddumage Avatar answered Nov 19 '22 01:11

Chamila Maddumage


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.

like image 31
Nate May Avatar answered Nov 19 '22 00:11

Nate May


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.

like image 6
Arsen Khachaturyan Avatar answered Nov 19 '22 00:11

Arsen Khachaturyan


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.

like image 3
Chathuranga Adikari Avatar answered Nov 19 '22 00:11

Chathuranga Adikari