Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Angular 6.1.2 PWA not working

General Tech Bugs & Fixes

Max. 2000 characters
Replies

usr_profile.png

User

( 6 months ago )

 

I tried all the solutions on the internet on how to add PWA to an Angular project, but still in Chrome Dev Tools, there are no service worker registered.

I did run ng add @angular/pwa, with ng build --prod and http-server -o and still no service worker registered. It also does not add a @angular/service-worker package and also no Manifest.jsonfile like it should as indicated all over the internet.

I also tried creating a new project with PWA pre-installed with ng new myProject --service-worker, also not working.

I even tried registering the service working like below:

if ( 'serviceWorker' in navigator ) { window.addEventListener('load', function() { navigator.serviceWorker.register('/service-worker.js'); });

A side note: When I run ng add @angular/pwa I get a message "Path '/ngsw-config.json' already exist", so I found out that file is under @schematics package. The script only adds a @angular/pwapackage, which does not corrolate with the Angular PWA docs.


Here is my environment :

Angular 6.1.2
Angular CLI: 6.1.3
Node 8.11.3
NPM  5.6.0

What do I need to do to get a plain PWA Angular project?

usr_profile.png

User

( 6 months ago )

It is the new version of @angular/pwa package that has a few bugs. So running ng add @angular/pwa@0.6.8 worked perfectly for me.

To test the service worker locally: If you have Firebase added to your project (hosting), you can run ng build --prod and then firebase serve. When you don't have Firebase, you can run ng build --prod, cd into the dist folder (depending on your config) and then run http-server -o. If you don't have http-server module, install it by running npm i -g http-server

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif