question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Service workers don't work

See original GitHub issue

Describe 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)

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rschristiancommented, Feb 27, 2021

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.

0reactions
yousefelgoharyxcommented, Feb 27, 2021

oh! ok thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is Service worker not working in Chrome? - Stack Overflow
In short: Service workers requires the site using them to be served over HTTPS for security reasons, but have execptions for localhost.
Read more >
Service worker doesn't work - WordPress.org
Hello! Service worker doesn't work. I had the same problem with this plugin: https://wordpress.org/plugins/super-progressive-web-apps/
Read more >
Using Service Workers - Web APIs | MDN
This article provides information on getting started with service workers, including basic architecture, registering a service worker, ...
Read more >
Service Worker doesn't work as expected · Issue #2499 - GitHub
The problem is: in the root page, it seems it is working, if you set the offline mode in the network and reload...
Read more >
Angular service worker introduction
For service workers to be registered, the application must be accessed over HTTPS, not HTTP. Browsers ignore service workers on pages that are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found