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

never get service-worker.js even with examples in the package #171

Open
ahmedB7r opened this issue Aug 1, 2019 · 26 comments
Open

never get service-worker.js even with examples in the package #171

ahmedB7r opened this issue Aug 1, 2019 · 26 comments

Comments

@ahmedB7r
Copy link

ahmedB7r commented Aug 1, 2019

Screenshot from 2019-08-01 07-01-30

i just always get this (pending) in the req , please help

@hanford
Copy link
Owner

hanford commented Aug 1, 2019

Can you share a repo where this issue is reproduce able? Given what you've shared it's impossible to tell what isn't working

@shahruz
Copy link

shahruz commented Aug 1, 2019

I think I've been having the same issue.

I grabbed now2-example and attempted to deploy it to now with version 15.8.7. The build failed at first over the generateInDevMode flag, removing that and redeploying created a successful build but I get the

SW registration failed: TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.

error now and trying to load /service-worker.js manually results in a 404 too. I'm guessing it's related to how now.json routes work with Next 9, which have been buggy in other ways for me the past few days.

I'd love to know if anyone's able to deploy that now2-example as-is right now and can get it to work! And thanks for the package @hanford!

@ahmedB7r
Copy link
Author

ahmedB7r commented Aug 2, 2019

sorry for low details but it even did that with now2-example and I do like @shahruz did and get the same errors! @hanford

@krishaamer
Copy link

Same here-

@hanford
Copy link
Owner

hanford commented Aug 5, 2019

@shahruz @ahmedB7r @krishaamer master is currently using an alpha version of workbox which has a known bug in it.GoogleChrome/workbox#2138

The Now 2.0 example on the 4.0 branch should work fine.

https://github.com/hanford/next-offline/tree/v4/examples/now2


Updated the version 5 beta to use the latest workbox version, which fixes the bug so the Now 2.0 example should work fine for both!

@shahruz
Copy link

shahruz commented Aug 5, 2019

That fixed it for me. Thanks!

@ahmedB7r
Copy link
Author

ahmedB7r commented Aug 5, 2019

it's worked thanks :) @hanford

@machiaveli88
Copy link

I run the now2-example and get this error: "Error: Cannot start server when target is not server". :(

@hanford
Copy link
Owner

hanford commented Aug 5, 2019

@machiaveli88 can you elaborate a little bit more?

how are you trying to start the now 2.0 example? when was the last time you pulled it down? (it was updated yesterday w/ some fixes)

@machiaveli88
Copy link

Hey, thanks for your answer!
I pulled now the new one and when try to build, I get the error Please check your GenerateSW plugin configuration: "generateInDevMode" is not a supported parameter.. yarn dev works without any errors/warnings.

@hanford
Copy link
Owner

hanford commented Aug 7, 2019

that should be fixed from this PR #176

Can you pull down and give it another try @machiaveli88

@skaptox
Copy link

skaptox commented Aug 7, 2019

that should be fixed from this PR #176

Can you pull down and give it another try @machiaveli88

Right now with that latest commit running yarn && yarn dev I am getting:

Please check your GenerateSW plugin configuration:
child "runtimeCaching" fails because ["runtimeCaching" at position 0 fails because [child "options" fails because ["expiration" missing required peer "cacheName"]]]

@antsitovichvlad
Copy link

that should be fixed from this PR #176
Can you pull down and give it another try @machiaveli88

Right now with that latest commit running yarn && yarn dev I am getting:

Please check your GenerateSW plugin configuration:
child "runtimeCaching" fails because ["runtimeCaching" at position 0 fails because [child "options" fails because ["expiration" missing required peer "cacheName"]]]

same error

@hanford
Copy link
Owner

hanford commented Aug 10, 2019

A contributor landed a fix for this: #177

Should be live in 5.0.0-beta.3 feel free to give it a try and report back! 🤞

This 5.0 release will be a large change, so I really appreciate the back and forth!

@machiaveli88
Copy link

machiaveli88 commented Aug 11, 2019

that should be fixed from this PR #176
Can you pull down and give it another try @machiaveli88

Right now with that latest commit running yarn && yarn dev I am getting:

Please check your GenerateSW plugin configuration:
child "runtimeCaching" fails because ["runtimeCaching" at position 0 fails because [child "options" fails because ["expiration" missing required peer "cacheName"]]]

same error

same here :(

yarn build & yarn start leads to SW registration failed: TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.

@hanford
Copy link
Owner

hanford commented Aug 11, 2019

@machiaveli88 So Now 2.0 works very differently than the other now examples. This example is only really running well when it's actually deploying to Now 2.0 it looks like.

The big gotcha here is Now 2.0 is handling all of the routing once deployed, whereas when running locally we're not getting that functionality.

In the now.json we're telling the now platform to handle all requests to /service-worker.js and redirect it to _next/static/service-worker.js - you can see that here: https://github.com/hanford/next-offline/blob/master/packages/now2-example/now.json#L6 ..

Zeit released something called now dev that should allow you to simulate this functionality during local development but I've not been successful with it.

I'm using Now 2.0 and next-offline on my personal website. The source is over here: https://github.com/hanford/personal-website and you can see that offline is working if you visit the url: https://jackhanford.com

@Siegrift
Copy link

Siegrift commented Sep 3, 2019

Thanks for this package, I really like the work you saved me :)

However I am experiencing the same issue (after running next dev):

child "runtimeCaching" fails because ["runtimeCaching" at position 0 fails because [child "options" fails because ["expiration" missing required peer "cacheName"]]]

These are my dependencies:

    "@material-ui/core": "^4.3.1",
    "@siegrift/tsfunct": "^1.3.2",
    "@types/jest": "^24.0.17",
    "@types/react-redux": "^7.1.1",
    "@types/redux-logger": "^3.0.7",
    "firebase": "^6.4.0",
    "next": "canary",
    "next-offline": "5.0.0-beta.3",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-redux": "^7.1.0",
    "redux": "^4.0.4",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.3.0",
    "ts-jest": "^24.0.2"

I am using canary next because I use firebase for deployment, and it works currently only in canary

Also, I tried rm -rf node_modules yarn.lock and install deps again, but got a few warnings:

warning next-offline > workbox-webpack-plugin > workbox-build > [email protected]: For compatibility with GitHub’s npm registry, this package has moved to @surma/rollup-plugin-off-main-thread
warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > [email protected]: use String.prototype.padStart()
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > [email protected]" has unmet peer dependency "webpack@^4.19.1".
warning "next-offline > [email protected]" has unmet peer dependency "webpack@^4.0.0".
[4/4] Building fresh packages...
success Saved lockfile.

When I tried next dev afterwards, got this error:

{ Error: Cannot find module 'workbox-build/build/entry-points/options/validate'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/siegrift/Documents/expense-manager-pwa/node_modules/workbox-webpack-plugin/build/generate-sw.js:18:18)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3) code: 'MODULE_NOT_FOUND' }

Have someone run into this as well, or knows what I am doing wrong? :)

@Siegrift
Copy link

Siegrift commented Sep 9, 2019

@hanford Do you have an idea what am I doing wrong?

@Siegrift
Copy link

Ok, first of all sorry for not including my next.config.js. I fixed my issue by setting generateInDevMode to false. My working config now looks like this:

const withOffline = require("next-offline");

// https://github.com/hanford/next-offline#now-20
const nextConfig = {
  // NOTE: this is present in the example, but breaks on dev
  // target: "serverless",
  transformManifest: manifest => ["/"].concat(manifest), // add the homepage to the cache
  // Trying to set NODE_ENV=production when running yarn dev causes a build-time error so we
  // turn on the SW in dev mode so that we can actually test it
  generateInDevMode: false,
  workboxOpts: {
    swDest: "static/service-worker.js",
    runtimeCaching: [
      {
        urlPattern: /^https?.*/,
        handler: "NetworkFirst",
        options: {
          cacheName: "https-calls",
          networkTimeoutSeconds: 15,
          expiration: {
            maxEntries: 150,
            maxAgeSeconds: 30 * 24 * 60 * 60 // 1 month
          },
          cacheableResponse: {
            statuses: [0, 200]
          }
        }
      }
    ]
  }
};

module.exports = withOffline(nextConfig);

@mattvb91
Copy link

same issue here "next-offline": "^5.0.0-beta.8"

@maysam
Copy link

maysam commented Jan 15, 2020

I think there should be a part in documentation for people who are not using 'now' and want to deploy it to their own host

@hanford
Copy link
Owner

hanford commented Jan 16, 2020

@maysam, I’d love a PR!

@Aditya94A
Copy link

Any updates on this? As a prospective dev looking at this repo, it's unclear whether PWAs via next-offline actually work fully?

@hanford
Copy link
Owner

hanford commented Feb 20, 2020

@AdityaAnand1 I'm considering removing the generateInDev mode flag, it seems like it's causing people more harm then good.

image

@karthik-js
Copy link

@hanford

using "next-offline": "^5.0.2",
configuration:
workboxOpts: { generateInDevMode: true, swDest: process.env.NEXT_EXPORT ? 'service-worker.js' : 'static/service-worker.js', runtimeCaching: [ { urlPattern: /^https?.*/, handler: 'NetworkFirst', options: { cacheName: 'offlineCache', expiration: { maxEntries: 200, }, }, }, ], },
Error:

`Failed to compile.

Please check your GenerateSW plugin configuration:
"generateInDevMode" is not a supported parameter.`

@hanford
Copy link
Owner

hanford commented Sep 9, 2020

@karthik-js it's possible generateInDevMode is totally broken. Remove that flag

#155

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