You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have just started using the next framework.I have read through the official document and also some of the chats at spectrum but I'm still unable to set up the next-offline in my project and get it started.
I'm currently just aiming at having atleast the service-worker registered in development.I'm not using "now" for deployment so as suggested have followed the "now 1" example in the documentation - the express server approach.
Here is the code for server.ts. The server.ts is inside the "server" folder in the root directory (next to "pages")
server.get('/service-worker.js', (req, res) => {
console.log('service worker called')
// Don't cache service worker is a best practice (otherwise clients wont get emergency bug fix)
res.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
res.set('Content-Type', 'application/javascript');
const filePath = join(__dirname, '.next', '/service-worker.js')
app.serveStatic(req, res, filePath)
});
I have created the next.config.js in the root directory. I haven't provided any workbox options yet for what I have understood is if we don't provide then the default would be taken.
however when I try to run the code in dev mode I get the following error
(node:6176) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type undefined
at readFile (fs.js:296:3)
Additional question -
I have prior knowledge of service workers and workbox. In its most basic form you define a sw.js at the root level and import the workbox plugin with an injection point. You could then register the service worker explicitly in the "parent" page or the "index" page.
The next-offline doc points that the registering script is already included but I'm still facing issues understanding how this works and why we have to rely on an express server by defining a custom route.
Any help would be appreciated.
Thanks ,
VP
The text was updated successfully, but these errors were encountered:
@Banzaci Hej ! no , I dropped the idea to use it. I agree with the documentation part , I found it confusing.
However I was able to solve that path error with this fix .
Also as far as the service workers are concerned with next-js , this article helped shed some light on it but I haven't really implemented that yet.
Hi,
I have just started using the next framework.I have read through the official document and also some of the chats at spectrum but I'm still unable to set up the next-offline in my project and get it started.
I'm currently just aiming at having atleast the service-worker registered in development.I'm not using "now" for deployment so as suggested have followed the "now 1" example in the documentation - the express server approach.
Here is the code for server.ts. The server.ts is inside the "server" folder in the root directory (next to "pages")
I have created the next.config.js in the root directory. I haven't provided any workbox options yet for what I have understood is if we don't provide then the default would be taken.
however when I try to run the code in dev mode I get the following error
(node:6176) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type undefined
at readFile (fs.js:296:3)
Additional question -
I have prior knowledge of service workers and workbox. In its most basic form you define a sw.js at the root level and import the workbox plugin with an injection point. You could then register the service worker explicitly in the "parent" page or the "index" page.
The next-offline doc points that the registering script is already included but I'm still facing issues understanding how this works and why we have to rely on an express server by defining a custom route.
Any help would be appreciated.
Thanks ,
VP
The text was updated successfully, but these errors were encountered: