Not Getting Service Worker With Create-react-app
Solution 1:
Thanks @jonrsharpe So, CRA does not give support for service worker directly with default installation command as developer may not be making the application as PWA. So, they decided to keep it optional. Like me, if you anyone else want to install service worker while creating a new app, Prefer:
npx create-react-app my-app --template cra-template-pwa
instead of default npx create-react-app my-app
.
Hence, for more yo can refer to https://create-react-app.dev/docs/making-a-progressive-web-app/
Solution 2:
If you have already existing project and you want to migrate to the new versions of CRA, you can follow this steps:
1 Create somewhere on your computer a new CRA with the service worker template:
npx create-react-app my-app --template cra-template-pwa
2 Copy the service-worker.js from the new created app into your src directory
3 Copy the "workbox-*" dependencies from the package.json into your package.json dependencies
4 (Optional) If you want web-vitals, copy the web-vitals dependency from package.json into your package.json
and don't forget to run again 'yarn install' or 'npm install'
Thats it
Solution 3:
run this command "npx create-react-app your-app-name --template cra-template-pwa" instead of "npx create-react-app your-app-name"
Solution 4:
you need to run this command
npx create-react-app your-app-name --template cra-template-pwa
instead of
npx create-react-app your-app-name
Post a Comment for "Not Getting Service Worker With Create-react-app"