-
Notifications
You must be signed in to change notification settings - Fork 110
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
Just can't get the file to serve in express, always shows a 404 #232
Comments
@focalstrategy I added this in another similar issue, does this solve your issue? |
That looks pretty promising - I’ll post back if this works. Thanks. |
(and with ../ like you had) With this as my next.config.js it still gets put into the same directory, doesn't get put in right place. I've tried So, seems that this doesn't change the behaviour of the plugin at all? Very weird! 😩 Edit: also tried literally pasting
as the only thing in next.config.js and no dice, still gets put into .next. |
@focalstrategy ah man. So I should also note (and should have before, sorry) that we're not using a custom server.js and just letting next use its default one. Do you need a custom server.js or are you just using it to try to get the service-worker working? If you don't need it then I'd try the above ^, but remove server.js |
Yeah, do need the custom server, is an existing site in production use. I might set up a new next.js app from scratch and see if it works there, really frustrating! |
Minimally trying to set this up I faced a similar issue. Instead of serving the file via the
got the service worker registered for me now. |
Facing the same issue (404, but the file is present) after updating from 9.1 to 9.3. Tried with the workaround given by @askwheeler with no success. Couldn't debug furthermore, code is minified after that. |
Opened an issue in next.js vercel/next.js#11751 |
I followed the example of now 2: https://github.com/hanford/next-offline/tree/master/packages/now2-example "rewrites": [
{
"source": "/service-worker.js",
"destination": "/_next/static/service-worker.js"
}
], I still can't test it on localhost (generateInDevMode: true) without the hack of doing an If anyone got a solution to work both in production and in localhost, tell us! :D |
@guilhermebruzzi I don't have a great solution for development mode at the moment. the GenerateInDev mode was a hack Anyways, I have this issue hoping someone else can come up with a good solution or at least a proposal |
I think you can have sth like this // next.config.js workboxOpts: {
swDest: 'static/service-worker.js',
runtimeCaching: [ // main.js // offline caching
get("/service-worker.js", (req, res) =>
nextApplication.serveStatic(req, res, `${process.cwd()}/.next/static/service-worker.js`)
), It will be able to work. serveStatic will only check in .next/static, static, public folder atm // Check if .next/static, static and public are in the path.
// If not the path is not available.
if ((untrustedFilePath.startsWith(path_1.join(this.distDir, 'static') + path_1.sep) ||
untrustedFilePath.startsWith(path_1.join(this.dir, 'static') + path_1.sep) ||
untrustedFilePath.startsWith(path_1.join(this.dir, 'public') + path_1.sep)) === false) {
return false;
} |
I'm using Next.js 9.3.3. I have this in server.js (among other things, the imports etc)
I've restarted the server with
npm run dev
a few times while testing.The path the console logs out:
/Users/MYUSERNAME/DIRNAME/.next/service-worker.js
is correct - if I check that file, it exists fine.However, I always hit the next.js error page which tells me 'An error 404 occurred on server'.
There are no errors on server.
Adding the Content-Type header means the error page HTML content doesn't render properly because it's sent as JS, so that part works at least…
This is driving me crazy - know it's not really this repo that's the problem, but can't for the life of me work out how to actually serve the file!
Any ideas? Thanks!
The text was updated successfully, but these errors were encountered: