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.

serve `service-worker.js` under `.next` folder is not possible any more after upgrading to `9.3.2`

See original GitHub issue

Bug report

I was making public .next/service-worker.js with express, but it is not possible anymore. Is there a way to serve this file? I know it because of a security issue but I was hoping to find a way.

Describe the bug

/service-worker.js 404

To Reproduce

Upgrade next to 9.3.2

server.js

server.get("/service-worker.js", function (req, res) {
    const filePath = join(__dirname, "./.next/", "service-worker.js");
    app.serveStatic(req, res, filePath);
  });

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
vhadjievcommented, Apr 3, 2020

nevermind, this worked

workboxOpts: {
  swDest: "../public/service-worker.js",
},

Yes, the config looks like this. You could add the service worker to your .gitignore so you don’t push it accidentally if you are testing something locally.

2reactions
vhadjievcommented, Apr 3, 2020

I had the same issue. My workaround is to set swDest: ../public/service-worker.js in workboxOpts configuration and now I can access the service worker without rules in my custom server

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Service worker (ngsw-worker.js) is not generated in ...
After running "ng build appname," I have a problem in that the Angular Service worker is not generated in the "/dist" folder.
Read more >
Fixing the Next.js Service Worker issue - Asap developers
When we create a React app, a Service Worker is invoked by default, so even if we unregister the Service Worker before deploying...
Read more >
How to adopt Next.js into your existing application
Learn how you can use Next.js in a pre-existing React application to add server-side rendering to your project.
Read more >
Adding a service worker into your Next.js application
After we have our service worker in place, we need to install it and we can do that when the page mounts. Next.js...
Read more >
The New Web: Part 3 – Setting Up The Front End ... - Intertech
Further, as a rule, your data in React may not be mutable. When ... It will create a new folder called “client”, and...
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