0
votes

Good evening, I'm trying to work with Reactjs and ServiceWorker to create a PWA but when creating a new project everything seems to work fine but when running npm run build and dispatch the result with npm's http-server opens the application correctly but the browser never records that there is a service worker.

I have already dealt with 3 projects and different browsers but everything remains the same. The projects are as they are installed with create-react-app.

Does anyone know why the service worker is not installed?

Attached image of how it is not registered by the browser even though it is in the build folder.

If I do this without using react as proof with a simple service worker file if I can register it but with reacrt I do not get it that way.

sw not registered

Thanks.

2
You might need to disable the HTTPS security verification. Services workers only work in HTTPS. - ChrisR

2 Answers

0
votes

Does you import your SW in the App entry point module? Example:

// index.js:

import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();  
0
votes

Thanks partners. I was able to solve it by modifying in line src / index.js the line 1 that I had:

serviceWorker.unregister();

By: serviceWorker.register();

And now it works.

Regards!