Service workers don't work
See original GitHub issueDescribe the bug
I’m using react with a service worker, anyhow when i build my app, everything goes fine except for the sw which wouldn’t exist in the dist directory. Let alone that the code used to get the sw has an undefined variable which is PUBLIC_URL which causes that error in the browser console:
GET http://127.0.0.1:5500/undefined/service-worker.js 404 (Not Found) (anonymous) @ index.e8abe765.js:10 (anonymous) @ index.e8abe765.js:10 load (async) (anonymous) @ index.e8abe765.js:10 (anonymous) @ index.e8abe765.js:10
Reproduction
just build a react app with a service worker
Please provide a link to a repo that can reproduce the problem you ran into. I don’t think it’s worth it
A reproduction is required unless you are absolutely sure that the the problem is obvious and the information you provided is enough for us to understand what the problem is. If a report has only vague description (e.g. just a generic error message) and has no reproduction, it will receive “need reproduction” label. If no reproduction is provided after 3 days, it will be auto-closed.
System Info
vite
version: 2.0.1- Operating System: Manjaro Gnome
- Node version: 12.19.0
- Package manager (npm/yarn/pnpm) and version: npm v 6.14.8
Logs (Optional if provided reproduction)
- Run
vite
orvite build
with the--debug
flag. - Provide the error log here.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
PUBLIC_URL
comes from the sw.js file you copied from CRA – it’s likely to be invalid when used anywhere else.You will need additional config as it’s looking for environment variables that aren’t set; they’re only set in CRA.
oh! ok thanks a lot!