Next.js: Next-offline is not working due to incorrect service-worker.js path

Created on 17 Nov 2019  路  7Comments  路  Source: vercel/next.js

Examples bug report

Example name

with-next-offline

Describe the bug

To be honest, the service-worker path configuration is so much complicated, and with "zero config:, like this example, it is not working.

To Reproduce

These are steps to reproduce platform-independently.

  1. clone next.js
  2. go in side : next.js/examples/with-next-offline
  3. run
docker run --rm -it -v "$pwd":/app -w /app -p 3000:3000 node:10.15.3-jessie npm i && npm run build && npm start
  1. Open localhost:3000 on browser, and see how pathetically it fails to load service-worker.js.
  2. additionally hit http://localhost:3000/service-worker.js and get a slapping 404, to be double sure.

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: No way, its docker
  • Browser : chrome
  • Version of Next.js: master

Additional context

In a lot of other issues of next-offline this problem is faced.

good first issue example

Most helpful comment

Let me have a look, thanks for pinging @lfades

All 7 comments

@pPanda-beta As per the with-next-offline README, you have to run npm run export instead of npm run build && npm start.

Let me know if your use case differs from serving content statically, I will be happy to fix it for you.

@aganglada I am experiencing same issue, as content is not served statically.

@pPanda-beta @kobbiman let me have a look and fix that example for you

@aganglada
Thank you for the fix.

I am having some issues with the with-next-offline example:

SW registration failed: DOMException: Failed to register a ServiceWorker for scope ('http://localhost:5000/') with script ('http://localhost:5000/service-worker.js'): The script has an unsupported MIME type ('text/html').

I followed the steps that are stated in the readme:
https://github.com/zeit/next.js/tree/canary/examples/with-next-offline

@aganglada ^

Let me have a look, thanks for pinging @lfades

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olifante picture olifante  路  3Comments

jesselee34 picture jesselee34  路  3Comments

sospedra picture sospedra  路  3Comments

kenji4569 picture kenji4569  路  3Comments

knipferrc picture knipferrc  路  3Comments