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
✓ Linting and checking validity of types
▲ Next.js 14.0.4
Environments: .env.local
✓ (serwist) Compiling for server...
✓ (serwist) Compiling for server...
✓ (serwist) Compiling for client (static)...
○ (serwist) Service worker: D:\code\roost\public\sw.js
○ (serwist) URL: /sw.js
○ (serwist) Scope: /
✓ Creating an optimized production build
✓ Compiled successfully
Collecting page data ...ReferenceError: self is not defined
at D:\code\roost.next\server\pages\sw.js:1:2979
Build error occurred
Error: Failed to collect page data for /sw
at D:\code\roost\node_modules\next\dist\build\utils.js:1220:15 {
type: 'Error'
}
Expected behavior
The project builds.
Screenshots (if relevant)
No response
Additional information (if relevant)
No response
The text was updated successfully, but these errors were encountered:
The error clearly indicates that Next.js is trying to build your file as a page, which it is not. Move it from pages/sw.js to something like sw/index.js. Unlike in App Router, you can't co-locate the service worker the way the docs suggests with your routes in Pages Router, for it will, too, be recognized as a route.
Provide environment information
Which project is this issue for?
@serwist/sw
Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster
https://projectisprivate-cantreplicate.com
To reproduce
Attempt to build Next.js with Serwist installed and configured to match the spec provided here;
https://serwist.pages.dev/docs/next/getting-started
On build (local and on netlify) the build fails stating that "self is not defined" and references sw.js
I am using the javascript implementation, not typescript.
sw.js
Describe the bug
✓ Linting and checking validity of types
▲ Next.js 14.0.4
✓ (serwist) Compiling for server...
✓ (serwist) Compiling for server...
✓ (serwist) Compiling for client (static)...
○ (serwist) Service worker: D:\code\roost\public\sw.js
○ (serwist) URL: /sw.js
○ (serwist) Scope: /
✓ Creating an optimized production build
✓ Compiled successfully
Collecting page data ...ReferenceError: self is not defined
at D:\code\roost.next\server\pages\sw.js:1:2979
Expected behavior
The project builds.
Screenshots (if relevant)
No response
Additional information (if relevant)
No response
The text was updated successfully, but these errors were encountered: