next-offline
next-offline copied to clipboard
never get service-worker.js even with examples in the package
i just always get this (pending)
in the req , please help
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
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!
sorry for low details but it even did that with now2-example
and I do like @shahruz did and get the same errors! @hanford
Same here-
@shahruz @ahmedB7r @krishaamer master is currently using an alpha version of workbox which has a known bug in it.https://github.com/GoogleChrome/workbox/issues/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!
That fixed it for me. Thanks!
it's worked thanks :) @hanford
I run the now2-example and get this error: "Error: Cannot start server when target is not server". :(
@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)
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.
that should be fixed from this PR https://github.com/hanford/next-offline/pull/176
Can you pull down and give it another try @machiaveli88
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"]]]
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
A contributor landed a fix for this: https://github.com/hanford/next-offline/pull/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!
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.
@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
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? :)
@hanford Do you have an idea what am I doing wrong?
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);
same issue here "next-offline": "^5.0.0-beta.8"
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
@maysam, I’d love a PR!
Any updates on this? As a prospective dev looking at this repo, it's unclear whether PWAs via next-offline actually work fully?
@AdityaAnand1 I'm considering removing the generateInDev mode flag, it seems like it's causing people more harm then good.
@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.`
@karthik-js it's possible generateInDevMode
is totally broken. Remove that flag
https://github.com/hanford/next-offline/issues/155