Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

now2 example app not working #261

Open
jfoz opened this issue Oct 7, 2020 · 1 comment
Open

now2 example app not working #261

jfoz opened this issue Oct 7, 2020 · 1 comment

Comments

@jfoz
Copy link

jfoz commented Oct 7, 2020

Steps taken:

  1. git clone https://github.com/hanford/next-offline.git
  2. cd next-offline/packages/now2-example/
  3. npm install
  4. npm run dev
  5. Open localhost:3000 in Google Chrome
  6. Check console.

Expected: Service worker registered.

Actual: 404 for http://localhost:3000/service-worker.js (screengrab below)

image

Apologies in advance in case I'm missing something.

@NateRadebaugh
Copy link

NateRadebaugh commented Nov 14, 2020

I'm also seeing this issue myself. My guess is the issue is due to the swDest field it's setting, since /static/ isn't a dir that is respected by nextjs anymore. However, I've tried using public/service-worker.js and also am seeing this error.

Edit:
I've found an "official" example in the nextjs codebase with a different config defined, which includes an explicit rewrites to point /service-worker.js at the real /_next/static/service-worker.js.

https://github.com/vercel/next.js/blob/canary/examples/with-next-offline/next.config.js

const withOffline = require('next-offline')

module.exports = withOffline({
  workboxOpts: {
    swDest: process.env.NEXT_EXPORT
      ? 'service-worker.js'
      : 'static/service-worker.js',
    runtimeCaching: [
      {
        urlPattern: /^https?.*/,
        handler: 'NetworkFirst',
        options: {
          cacheName: 'offlineCache',
          expiration: {
            maxEntries: 200,
          },
        },
      },
    ],
  },
  async rewrites() {
    return [
      {
        source: '/service-worker.js',
        destination: '/_next/static/service-worker.js',
      },
    ]
  },
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants