Search code examples
reactjsfrontendservice-workerscaffolding

Why does my create-react-app have no service workers?


I used the simplest and the dumbest command

npx create-react-app mia-app
cd mia-app
npm start

But after created the project everytime there are no serviceWorker. Can someone help me?

enter image description here enter image description here

However, I've tried with npm create-create-app with this res.

enter image description here


Solution

  • serviceWorker.js is no longer included in the base template, as of create-react-app version 4.0.something.

    Trawling through the create-react-app GitHub issues, two main workarounds keep popping up:

    1. Create an app using the following template:
    npx create-react-app my-app --template cra-template-pwa
    

    or for Typescript:

    npx create-react-app my-app --template cra-template-pwa-typescript
    

    (where my-app is replaced by the name of your app)

    1. If you already have an existing project, create a dummy app and copy over the relevant code. Don't forget to copy over the initialisation code from index.js/index.tsx if you do this too.