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
Serving the ServiceWorker #103
Comments
I have the same problem. Any help would be great! |
@PatrickSachs can you maybe clarify how you're using the |
@dandrei Which setting are you using for For easy HTTPS support I'd recommend you to take a look at my redoubt library which handles all the HTTPS stuff in the background for you: https://github.com/PatrickSachs/redoubt @hanford By default a stub file is used as device worker if |
I didn't have it set before. I set the two variables to the values suggested in #97, but now I have another issue, the client compilation gets stuck at 95%:
Here's the relevant part of the config (not sure about the items in
|
Validation errors are hidden in development mode. If you run your build script you'll see the error: name: 'ValidationError',
details:
[ { message: '"precacheManifest" is not a supported parameter.',
path: [Array],
type: 'object.allowUnknown',
context: [Object] } ]
// .... |
You're right. I copied the config from the web. That particular parameter must have gotten deprecated and removed from Workbox at some point. Now I'm running with a minimum configuration:
I get
The stacktrace points to this line
in |
@dandrei could you share a repository where this issue is easy to reproduce? It would help me debug this issue much faster, thanks! |
just wondering if this was fixed or if there is a version of next-offline that works? I keep getting a failed to load service-worker.js error when communicating to server and none seems to be generated. |
@jackgray I can't fix bugs if they can't be replicated. I need consistently reproducible repository to take a deeper look at this issue. I'd also be happy to merge/review a PR if you think you've fixed it. I've never had this issue and I've used next-offline numerous times. There are many examples of next-offline working fine, you can see the examples folder or check out my personal website or a different side project trends |
Going to go ahead and close this issue. I can't really look in more without some sample code or a reproduction case. I'd make sure you have a server or now.json set up to serve the server-worker GET request. Feel free to comment again again or open another issue if you have any other issues |
This could be related to #127 |
I'll answer because I think there is some misunderstanding from users, I'll make some pull request to the documentation soon to clarify some things that might not be easy to understand when you're new to service workers. In order to use any service worker in development mode with nextJS you must rely on custom development server. Just create a new file at root project folder called const { createServer } = require("http");
const { join } = require("path");
const { parse } = require("url");
const next = require("next");
const app = next({ dev: process.env.NODE_ENV !== "production" });
const handle = app.getRequestHandler();
app.prepare().then(() => {
createServer((req, res) => {
const parsedUrl = parse(req.url, true);
const { pathname } = parsedUrl;
// handle GET request to /service-worker.js
if (pathname === "/service-worker.js") {
const filePath = join(__dirname, ".next", pathname);
app.serveStatic(req, res, filePath);
} else {
handle(req, res, parsedUrl);
}
}).listen(3000, () => {
console.log(`> Ready on http://localhost:${3000}`);
});
}); See the statement ?
That's because if you look into The above server script solve the issue by allowing a root URL to serve a specific file which is the one generated using |
PR's are welcome @ScreamZ ! |
Hey everyone,
I'm trying to add offline support to my Next.js app. I did the following so far:
next-offline
next.config.js
(module.exports = withOffline(__config__
);next.config.js
:yarn dev
.Here I ran into a bit of trouble. I get:
Looks like the script is trying to fetch the SW from
/service-worker.js
, but Next.js doesn't serve it on that route and just returns a 404.So that's the first question: how to get the SW to be served? Is it supposed to be automatically generated by
next-offline
, or should I manually create this file myself?The second question has to do with the protocol. Next.js runs out of the box on HTTP (not HTTPS). But SWs are designed to run on HTTPS. How is this usually addressed?
Thanks!
The text was updated successfully, but these errors were encountered: