The code right about that comment is the code sample that will make it work in dev mode. Let me try to explain it a little better-
if (‘serviceWorker’ in navigator) {
return new Promise((resolve, reject) => {
window.addEventListener(‘load’, () => {
const swUrl = process.env.NODE_ENV === ‘production’? ‘/service-worker.js’: ‘/custom-service-worker.js’;
// Rest of the code follows
So, in this code, what is happening is that on event load, CRA is trying to find the location of the service worker. In production, this service worker is created for you by CRA and the ‘service-worker.js’ file is generated. However, since this only works on npm build, in order for us to launch our service worker in dev mode, we create the ‘custom-service-worker.js’ file and provide it to CRA like the above snippet shows.
So this way, by checking NODE_ENV, even in dev mode, we can provide a custom service worker file, which will implement the push notification logic. It won’t have the caching functionality that CRA provides on npm build, but the push notifications should work in dev mode this way