Git Product home page Git Product logo

serwist's Introduction

serwist's People

Contributors

3846masa avatar addyosmani avatar arcanis avatar azizhk avatar ducanhgh avatar github-actions[bot] avatar jeffposnick avatar joshkel avatar jpmedley avatar kaykayehnn avatar markbrocato avatar markgoho avatar matthewjmay avatar merrywhether avatar mikeybelike avatar mungojam avatar ognjenjevremovic avatar peterjosling avatar philipwalton avatar philkrie avatar piotr-cz avatar prateekbh avatar salmoro avatar samdutton avatar samthor avatar sethbergman avatar sircelsius avatar snugug avatar tropicadri avatar xmokax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

serwist's Issues

[Bug]: Webpack config

Provide environment information

^8.40

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

none

To reproduce

Add a custom webpack configuration to your nextjs config file

Describe the bug

This is my webpack config:

webpack: (config) => {
    //? zlib-sync
    config.resolve.fallback = {
      "zlib-sync": false,
      "utf-8-validate": false,
      bufferutil: false,
    }

    return config
  },

I need it due to a problem with of another package and next.js (discord.js)
But your package completly override this so the build doesn't work anymore

Expected behavior

Take my config before the add your own

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Bug]: Googletagmanager fails to load on safari with the default @serwist/next package

Provide environment information

  • Using the latest @serwist/next (also occurs with next-pwa or @ducanh2912/next-pwa)
  • Usingimport { defaultCache } from "@serwist/next/browser"; to configure the runtimeCache.
  • Have googletagmanager injected with the default script in a next.js installation

Which project is this issue for?

None

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://www.da.nl/ (has since been fixed though)

To reproduce

  1. On the first load the service worker isn't initialized, gtm loads
  2. On the second load the first request goes through the serviceworker, gtm loads
  3. On the third load gtm doesn't load

Describe the bug

This part is causing issues, if I comment this out in the defaultCache, it starts to work:

  {
    urlPattern: ({ sameOrigin }) => !sameOrigin,
    handler: 'NetworkFirst',
    options: {
      cacheName: 'cross-origin',
      expiration: {
        maxEntries: 32,
        maxAgeSeconds: 60 * 60,
      },
      networkTimeoutSeconds: 10,
    },
  },

I'm not even sure if you'd want to have third party scripts loaded on the site as there is a very low chance that it works offline and the maxAgeSeconds doesn't really add anything besides default browser cache?

Expected behavior

For now we've commented out the caching of cross origin scripts as we're not sure what the value is in this case. But I guess it should at least be opt-in.

Screenshots (if relevant)

Scherm_afbeelding 2024-02-26 om 14 37 35

Additional information (if relevant)

No response

[Bug]: dest property instead of swDest in WebpackInjectManifest

Provide environment information

  • @serwist/next: 8.3.0
  • @serwist/sw: 8.3.0
  • next: 14.0.4
  • react: 18.2.0
  • react-dom: 18.2.0
  • webpack: 5.89.0

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

NA

To reproduce

  • yarn init -y
  • yarn set version berry
  • yarn add next react react-dom @serwist/next @serwist/sw webpack
  • create empty pages folder
  • create next.config.mjs
import withPWA from '@serwist/next'

const isDev = process.env.NODE_ENV === 'development'

const nextConfig = {}

export default withPWA({
  dest: 'public',
  disable: isDev,
  cacheOnFrontEndNav: true,
  swSrc: 'app/sw.js',
  swDest: 'public/sw.js'
})(nextConfig)
  • yarn next build
   ▲ Next.js 14.0.4
   - Environments: .env

 ✓ (serwist) Compiling for server...
 ✓ (serwist) Compiling for server...
 ✓ (serwist) Compiling for client (static)...
 ○ (serwist) Service worker: C:\<PROJECT_NAME>\public\sw.js
 ○ (serwist)   URL: /sw.js
 ○ (serwist)   Scope: /
Failed to compile.

Please check your InjectManifest plugin configuration:
[WebpackInjectManifest] 'dest' property is not expected to be here. Did you mean property 'swDest'?

Cannot read properties of undefined (reading 'source')

Describe the bug

The build phase fails with error:

Please check your InjectManifest plugin configuration:
[WebpackInjectManifest] 'dest' property is not expected to be here. Did you mean property 'swDest'?

Cannot read properties of undefined (reading 'source')

The error should be related to InjectManifest of @serwist/webpack-plugin.

Expected behavior

Build is completed with no errors

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Docs]: Next.js, where are the cache expiration settings and similar configuration

Provide environment information

package.json:

{
	"dependencies": {
		"@aws-crypto/sha256-browser": "^5.2.0",
		"@babel/preset-react": "^7.23.3",
		"@fortawesome/fontawesome-svg-core": "^6.4.2",
		"@fortawesome/free-brands-svg-icons": "^6.4.2",
		"@fortawesome/free-regular-svg-icons": "^6.4.2",
		"@fortawesome/free-solid-svg-icons": "^6.4.2",
		"@fortawesome/react-fontawesome": "^0.2.0",
		"@headlessui/react": "^1.7.17",
		"@hotjar/browser": "^1.0.9",
		"@sentry/nextjs": "^7.82.0",
		"@sentry/react": "^7.82.0",
		"@sentry/tracing": "^7.82.0",
		"@serwist/next": "^8.4.4",
		"@serwist/sw": "^8.4.4",
		"@types/jest": "^29.5.11",
		"colors-convert": "^1.4.1",
		"core-js": "^3.33.3",
		"framer-motion": "^10.16.5",
		"ga-gtag": "^1.2.0",
		"intersection-observer": "^0.12.2",
		"js-base64": "^3.7.5",
		"js-xxhash": "^3.0.1",
		"lodash": "^4.17.21",
		"lodash.groupby": "^4.6.0",
		"lodash.throttle": "^4.1.1",
		"lozad": "^1.16.0",
		"lzwcompress": "^1.1.0",
		"md5": "^2.3.0",
		"mobx": "^6.12.0",
		"mobx-react": "^9.1.0",
		"mobx-state-tree": "^5.4.0",
		"next": "^14.0.3",
		"next-cookies": "^2.0.3",
		"next-themes": "^0.2.1",
		"omit-deep-lodash": "^1.1.7",
		"overlayscrollbars": "^2.4.5",
		"overlayscrollbars-react": "^0.5.3",
		"pako": "^2.1.0",
		"rc-slider": "^10.4.0",
		"react": "^18.2.0",
		"react-dom": "^18.2.0",
		"react-gtm-module": "^2.0.11",
		"react-hook-form": "^7.48.2",
		"react-hotkeys-hook": "^4.4.1",
		"react-input-slider": "^6.0.1",
		"react-query": "^3.39.3",
		"regenerator-runtime": "^0.14.0",
		"swr": "^2.2.4",
		"use-onclickoutside": "^0.4.1",
		"usehooks-ts": "^2.9.1",
		"uuid": "^9.0.1"
	},
	"devDependencies": {
		"@babel/eslint-parser": "^7.23.3",
		"@babel/preset-env": "^7.23.3",
		"@babel/preset-typescript": "^7.23.3",
		"@next/eslint-plugin-next": "^14.0.3",
		"@playwright/test": "^1.40.0",
		"@testing-library/jest-dom": "^4.2.4",
		"@testing-library/react": "^14.2.0",
		"@types/lodash.throttle": "^4.1.9",
		"@types/node": "^20.10.0",
		"@types/react": "18.2.39",
		"@types/react-dom": "18.2.17",
		"@types/react-modal": "^3.16.3",
		"@types/styled-components": "^5.1.32",
		"@types/testing-library__jest-dom": "^6.0.0",
		"@typescript-eslint/eslint-plugin": "^6.13.1",
		"@typescript-eslint/parser": "^6.13.1",
		"autoprefixer": "10.4.16",
		"babel-jest": "^29.7.0",
		"babel-plugin-transform-dynamic-import": "^2.1.0",
		"eslint": "8.54.0",
		"eslint-config-airbnb-typescript": "^17.1.0",
		"eslint-config-next": "^14.0.3",
		"eslint-config-prettier": "^9.0.0",
		"eslint-import-resolver-node": "^0.3.9",
		"eslint-plugin-eslint-comments": "^3.2.0",
		"eslint-plugin-import": "^2.29.0",
		"eslint-plugin-jsx-a11y": "^6.8.0",
		"eslint-plugin-prettier": "^5.0.1",
		"eslint-plugin-promise": "^6.1.1",
		"eslint-plugin-react": "^7.33.2",
		"eslint-plugin-react-hooks": "^4.6.0",
		"eslint-plugin-simple-import-sort": "^10.0.0",
		"eslint-plugin-unicorn": "^49.0.0",
		"eslint-plugin-unused-imports": "^3.0.0",
		"eslint-webpack-plugin": "^4.0.1",
		"husky": "^8.0.3",
		"jest": "^29.7.0",
		"jest-environment-jsdom": "^29.7.0",
		"lint-staged": "^15.1.0",
		"postcss": "8.4.31",
		"prettier": "^3.1.0",
		"sass": "^1.69.5",
		"standard-version": "^9.5.0",
		"stylelint": "^15.11.0",
		"stylelint-config-standard": "^34.0.0",
		"stylelint-scss": "^5.3.1",
		"tailwindcss": "3.3.5",
		"ts-jest": "^29.1.2",
		"turbo": "^1.10.16",
		"typedoc": "^0.25.4",
		"typedoc-plugin-markdown": "^3.17.1",
		"typescript": "^5.3.3"
	},
}

next.config.js:

const withSerwist = require("@serwist/next").default({
	swSrc: "src/lib/pwa/sw.ts",
	swDest: "public/sw.js",
	scope: "/",
	maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
	reloadOnOnline: false,
})

sw.ts:

installSerwist({
	precacheEntries: self.__SW_MANIFEST,
	skipWaiting: true,
	clientsClaim: true,
	navigationPreload: true,
	runtimeCaching:  [
		{
			urlPattern: /https:\/\/(cdn\..*\.ourdomain
\.com).*/,
			handler: 'CacheFirst',
			options: {}, // needed to avoid serwist crash
		},
		...defaultCache],
})

Describe the problem

First of all, thank you for this library. We really appreciate your work and efforts.

My problem: we have a project in production since 8 months, using Next 14.
Three days ago we deployed a version that implements @Serwist/next.
We noticed a HUGE spike in server requests (20X at some point).

2024-03-08_15-34

CPU usage of our nodes increased 2/3X, same for out bandwidth usage.

No particular Serwist configuration. All the images and assets (except favicon and fonts) are in on a CDN.

Expected behavior

We were expecting the opposite, less server load in general.
Is there any way of reducing the requests Serwist does on the server?

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Bug]: various issues in either next.config.js or next.config.mjs

Provide environment information

package version
@serwist/next ^8.4.0
@serwist/precaching ^8.4.0
@serwist/sw ^8.4.0
next ^14.0.4
next-contentlayer ^0.3.4
contentlayer ^0.3.4

Which project is this issue for?

None

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://github.com/marcofranssen/nextjs-blog/tree/switch-to-serwist

To reproduce

Create a nextjs project using contentlayer.

Describe the bug

As soon I switch to serwist from @ducanh2912/next-pwa it fails. I tried both next.config.js and next.config.mjs approaches.

When using the .mjs approach I'm seeing following error:

$ pnpm dev

> [email protected] dev /Users/marco/code/priv/nextjs-blog
> next dev

   ▲ Next.js 14.0.4
   - Local:        http://localhost:3000
   - Environments: .env

 ○ (serwist) PWA support is disabled.
 ○ (serwist) PWA support is disabled.
 ✓ Ready in 6.8s
Contentlayer config change detected. Updating type definitions and data...
Generated 76 documents in .contentlayer
<w> [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Parsing of /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected][email protected]/node_modules/@contentlayer/core/dist/dynamic-build.js for build dependencies failed at 'import(`file://${compiledConfigPath}`)'.
<w> Build dependencies behind this expression are ignored and might cause incorrect cache invalidation.
<w> [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Parsing of /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected][email protected]/node_modules/@contentlayer/core/dist/getConfig/index.js for build dependencies failed at 'import(`file://${modulePath}?x=${Date.now()}`)'.
<w> Build dependencies behind this expression are ignored and might cause incorrect cache invalidation.
<w> [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Parsing of /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected][email protected]/node_modules/@contentlayer/core/dist/generation/generate-dotpkg.js for build dependencies failed at 'import(filePathJoin(generatedPkgPath, 'generated', 'index.mjs'))'.
<w> Build dependencies behind this expression are ignored and might cause incorrect cache invalidation.
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can't resolve 'markdown-wasm/dist/markdown.node.js' in '/Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected][email protected]/node_modules/@contentlayer/core/dist/markdown'
<w> while resolving 'markdown-wasm/dist/markdown.node.js' in /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected][email protected]/node_modules/@contentlayer/core/dist/markdown as file
<w>  at resolve esm file markdown-wasm/dist/markdown.node.js
<w>  at file dependencies /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected][email protected]/node_modules/@contentlayer/core/dist/markdown/markdown.js
<w>  at file /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected][email protected]/node_modules/@contentlayer/core/dist/markdown/markdown.js
<w>  at resolve esm file ./markdown/markdown.js
<w>  at file dependencies /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected][email protected]/node_modules/@contentlayer/core/dist/index.js
<w>  at file /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected][email protected]/node_modules/@contentlayer/core/dist/index.js
<w>  at resolve esm file @contentlayer/core
<w>  at file dependencies /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/next-contentlayer/dist/plugin.js
<w>  at file /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/next-contentlayer/dist/plugin.js
<w>  at resolve esm file ./plugin.js
<w>  at file dependencies /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/next-contentlayer/dist/index.js
<w>  at file /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/next-contentlayer/dist/index.js
<w>  at resolve esm file next-contentlayer
<w>  at file dependencies /Users/marco/code/priv/nextjs-blog/next.config.mjs
<w>  at file /Users/marco/code/priv/nextjs-blog/next.config.mjs
<w>  at resolve commonjs /Users/marco/code/priv/nextjs-blog/next.config.mjs

See here the next.config.mjs.

import { withContentlayer } from "next-contentlayer";
import withSerwistInit from "@serwist/next";

const withSerwist = withSerwistInit({
  swSrc: "app/sw.ts",
  swDest: "public/sw.js",
  disable: process.env.NODE_ENV === "development",
});

export default withContentlayer(
  withSerwist({})
);

I also tried using a regular next.config.js.

const withSerwist = require("@serwist/next").default({
  swSrc: "app/sw.ts",
  swDest: "public/sw.js",
  disable: process.env.NODE_ENV === "development",
});
const { withContentlayer } = require("next-contentlayer");

module.exports = withContentlayer(
  withSerwist({})
);

This results in following error.

pnpm dev

> [email protected] dev /Users/marco/code/priv/nextjs-blog
> next dev

/Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected]/node_modules/@serwist/build/dist/index.cjs:65
    glob pattern strings.`,
                           ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/[email protected]/node_modules/stringify-object/index.js from /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected]/node_modules/@serwist/build/dist/index.cjs not supported.
Instead change the require of index.js in /Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected]/node_modules/@serwist/build/dist/index.cjs to a dynamic import() which is available in all CommonJS modules.
    at mod.require (/Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/next/dist/server/require-hook.js:65:28)
    at Object.<anonymous> (/Users/marco/code/priv/nextjs-blog/node_modules/.pnpm/@[email protected]/node_modules/@serwist/build/dist/index.cjs:13:23) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v20.10.0
 ELIFECYCLE  Command failed with exit code 1.

Expected behavior

The project just compiles and works like before when using @ducanh2912/next-pwa.

Screenshots (if relevant)

No response

Additional information (if relevant)

My repo is private, but I can add a maintainer of the project to troubleshoot, also happy to provide more information if you tell me what debug steps to take to provide more details.

[Bug]: Serwist is failing to compile for the client if the project has imports of JSON modules

Provide environment information

Node.js: 20.11
Next.js: 14.04

Used packages:

  • @serwist/sw
  • @serwist/next
  • @serwist/precaching
  • @serwist/build

Tested all from v8.3.0 to v8.4.2 (some versions had the issue mentioned by #34).

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://codesandbox.io/p/devbox/serwist-json-modules-dg6jz3?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clr9fcls00007356i8x2u4dwl%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clr9fcls00002356i5sxhiuk0%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clr9fcls00004356ih00uxfwd%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clr9fcls00006356img794hnv%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clr9fcls00002356i5sxhiuk0%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clr9fcls00001356isrgz3usx%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252FREADME.md%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%252C%2522id%2522%253A%2522clr9fcls00002356i5sxhiuk0%2522%252C%2522activeTabId%2522%253A%2522clr9fcls00001356isrgz3usx%2522%257D%252C%2522clr9fcls00006356img794hnv%2522%253A%257B%2522id%2522%253A%2522clr9fcls00006356img794hnv%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clr9fcls00005356i3if10me6%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522port%2522%253A3000%252C%2522path%2522%253A%2522%252F%2522%257D%255D%252C%2522activeTabId%2522%253A%2522clr9fcls00005356i3if10me6%2522%257D%252C%2522clr9fcls00004356ih00uxfwd%2522%253A%257B%2522id%2522%253A%2522clr9fcls00004356ih00uxfwd%2522%252C%2522activeTabId%2522%253A%2522clr9fcs5i004x356ik7xuh1xp%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clr9fcls00003356i9swj7rju%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%257D%252C%257B%2522id%2522%253A%2522clr9fcs5i004x356ik7xuh1xp%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522clr9fcsqg00b5eege5rim9243%2522%257D%255D%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

To reproduce

NOTE: I couldn't reproduce the issue on the provided sandbox.

Here is some context in case it helps:
My app is pretty complex and has a lot of modules and abstractions. The take is, I have localizations files in JSON formats that are provided to the client by a provider via a server component to handle translations on the client side. These JSON files are added to the built assets at the end, are thus are part of the client code. When building the app, Serwist is complaining about these file because webpack fails to parse the files (see screenshots below).

Describe the bug

If JSON modules are imported and are part of the build, webpack parser fails. From my research online, the issue may have to do with webpack JSON loader.

BTW, "(serwist) Compiling for server" is finishing successfully, but "Compiling for client (static)..." is failing.

Expected behavior

The app should be built as expected (when disabling Serwist via configuration, the app is built successfully)

Screenshots (if relevant)

image
image

Additional information (if relevant)

No response

Cannot find package 'webpack'

I got error Cannot find package 'webpack' and I assume you've missed to add npm i -D webpack in the installation part of getting started, since I've found difference on the former package(@ducanh2912/next-pwa - ex npm i @ducanh2912/next-pwa && npm i -D webpack).

npm: {
code: "npm i @serwist/next",
lang: "bash",
},
yarn: {
code: "yarn add @serwist/next",
lang: "bash",
},
pnpm: {
code: "pnpm add @serwist/next",
lang: "bash",
},
bun: {
code: "bun add @serwist/next",
lang: "bash",
},

If you think this is true, maybe I can add several code lines in the docs thorough PR.

[Bug]: Problem with old safari version

Provide environment information

Next.js 14.
No particular configuration.

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

Unfortunately it is a private repository.

To reproduce

Open a serwist website in Safari 14 or below and check the developer console.

Describe the bug

We've noticed that after deploying @Serwist/next we start getting frontend reports of errors like this

SyntaxError: Unexpected token '='. Expected an opening '(' before a method's parameter list.

After checking it, we realized it was only happening with MacOS X 10.15.6 and browser Apple Mail 605.1.15.

The error appeared in main.js and it was on the Serwist part.

The website doesn't load because of this.

After doing some research in the code, the problem comes from parts of the code like

class SerwistEvent {
    type;
    target;
    sw;
    originalEvent;
    isExternal;
    ...
}

or

    _eventListenerRegistry = new Map();
    ...
}

We've been able to fix it using next-transpile-modules, something like this

const withTM = require('next-transpile-modules')(['@serwist/window']);

/** @type {import('next').NextConfig} */
module.exports = withTM(withSerwist({

Of course, it is nice that it works with this workaround, but wanted to share the problem in case you weren't aware of it.

Expected behavior

To be able to load the website.

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Bug]: When using serwist/next with pyodide/webpack-plugin - "TypeError: The 'compilation' argument must be an instance of Compilation"

Provide environment information

With Next 14.03

├─┬ @pyodide/[email protected] overridden
│ └─┬ [email protected]
│ └── [email protected] deduped
├─┬ @serwist/[email protected]
│ └─┬ @serwist/[email protected]
│ └── [email protected] deduped
└─┬ [email protected]
└─┬ [email protected]
└─┬ [email protected]
└── [email protected] deduped

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

N/A

To reproduce

  1. Attempt to configure webpack like so for Pyodide and Serwist
//next.config.mjs
import { PyodidePlugin } from "@pyodide/webpack-plugin"
import withSerwistInit from "@serwist/next"

const withSerwist = withSerwistInit({
	swSrc: "app/sw.ts",
	swDest: "public/sw.js",
})

/** @type {import('next').NextConfig} */
export default withSerwist({
	webpack: (config, { isServer }) => {
		if (!isServer) {
			config.plugins.push(new PyodidePlugin())
		}
		if (isServer) {
			config.externals = ["pyodide", ...(config.externals || [])]
		}
		return config
	},
})
  1. Attempt to npm run dev for it to fail with logs
TypeError: The 'compilation' argument must be an instance of Compilation
    at NormalModule.getCompilationHooks (/Users/gabriel/dev/colorchordsapp/node_modules/webpack/lib/NormalModule.js:241:10)
    at file:///Users/gabriel/dev/colorchordsapp/node_modules/@pyodide/webpack-plugin/plugin.mjs:314:99
    at Hook.eval [as call] (eval at create (/Users/gabriel/dev/colorchordsapp/node_modules/next/dist/compiled/webpack/bundle5.js:13:28645), <anonymous>:122:1)
    at Hook.CALL_DELEGATE [as _call] (/Users/gabriel/dev/colorchordsapp/node_modules/next/dist/compiled/webpack/bundle5.js:13:25915)
    at Compiler.newCompilation (/Users/gabriel/dev/colorchordsapp/node_modules/next/dist/compiled/webpack/bundle5.js:28:147694)
    at /Users/gabriel/dev/colorchordsapp/node_modules/next/dist/compiled/webpack/bundle5.js:28:148481
    at Hook.eval [as callAsync] (eval at create (/Users/gabriel/dev/colorchordsapp/node_modules/next/dist/compiled/webpack/bundle5.js:13:28867), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/gabriel/dev/colorchordsapp/node_modules/next/dist/compiled/webpack/bundle5.js:13:26021)
    at Compiler.compile (/Users/gabriel/dev/colorchordsapp/node_modules/next/dist/compiled/webpack/bundle5.js:28:148407)
    at /Users/gabriel/dev/colorchordsapp/node_modules/next/dist/compiled/webpack/bundle5.js:28:489605
  1. Searching online for the error and realize it's typically caused by multiple webpack dependencies of different version
  2. Run npm dedupe to rerun and see same error

Describe the bug

Apologies I'm new to webpack configurations and webworkers but I'm trying to use Serwist to handle the caching of Pyodide's large wasm .whl/.zip files it needs to serve to the client.

Notably Pyodide's support of Next.js and similar frameworks is circumstantial at best but I've gotten it to work well with enough fiddling. Pyodide team provides a webpack-plugin for itself due to an errors like such that will happen:

Module build failed: UnhandledSchemeError: Reading from "node:child_process" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:child_process
./node_modules/pyodide/pyodide.mjs
./scripts/pyodide/PyodideManager.ts
./scripts/hooks/usePyodide.ts
./inputs/providers/CompanionContextProvider/CompanionContextProvider.tsx
./inputs/providers/CompanionContextProvider/index.tsx
./components/LiveCompanion/LiveCompanionView/LiveCompanionView.tsx

I'm not sure if someone here would know if this is something that can be worked around. Thanks in advance.

Expected behavior

npm run dev starts up without issue

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Docs]:// Change this attribute's name to your `injectionPoint`.

Provide environment information

Working on Windows with latest versions of nextjs and nodejs

Describe the problem

I m using the import type { PrecacheEntry } from '@serwist/precaching' and there its written that I have to Change the attribute's name to your 'injectionPoint'. And Its throwing error Cannot find name 'ServiceWorkerGlobalScope'. Did you mean 'ServiceWorkerGlobalScopeEventMap'?ts(2552). I m new to PWA and Its my 1st time setting up this, so I don't know what to do. Will be really helpful, if anyone can explain what exactly I have to do ??

Expected behavior

Dont Know

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Bug]: Service Worker is installed on a page out of scope.

Provide environment information

"@serwist/next": "^8.4.4",
"@serwist/precaching": "^8.4.4",
"@serwist/sw": "^8.4.4",

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

None

To reproduce

next.config.(m)js:

  swUrl: "/app/sw.js",
  scope: "/app/",

Then access to /.

Describe the bug

If I set scope to /app/ and swUrl to /app/sw.js in next.config.(m)js, the sw.js is installed when I opened the page /.

Expected behavior

sw.js is not installed on a page out of scope.

Screenshots (if relevant)

image

Additional information (if relevant)

Setting register to false in next.config.(m)js and calling window.serwist.register() manually is a workaround.

[Docs]: Can you update with an example for sub domain like app.acme.com

Provide environment information

How do we setup service worker for sub domains

Describe the problem

Can you update with an example for sub domain like app.acme.com

Expected behavior

Need a document to showcase on sub domains.

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Bug]: ERR_REQUIRE_ESM on @serwist/build

Provide environment information

{
  "name": "roost",
  "version": "0.2.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^6.2.0",
    "@fortawesome/free-brands-svg-icons": "^6.2.0",
    "@fortawesome/free-regular-svg-icons": "^6.2.0",
    "@fortawesome/free-solid-svg-icons": "^6.2.0",
    "@fortawesome/react-fontawesome": "^0.2.0",
    "@serwist/next": "^8.4.0",
    "@serwist/precaching": "^8.4.0",
    "@serwist/sw": "^8.4.0",
    "isomorphic-unfetch": "^3.1.0",
    "js-cookie": "^3.0.1",
    "luxon": "^3.3.0",
    "moment": "^2.29.4",
    "next": "^14.0.4",
    "next-cookies": "^2.0.3",
    "normalize.css": "^8.0.1",
    "octokit": "^3.1.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-hot-toast": "^2.4.0",
    "react-image-gallery": "^1.2.11",
    "react-modal": "^3.16.1",
    "react-tabs": "^5.1.0",
    "react-twemoji": "^0.5.0",
    "rss-parser": "^3.13.0",
    "snoowrap": "^1.23.0"
  },
  "devDependencies": {
    "eslint": "^8.56.0",
    "eslint-config-next": "^14.0.4",
    "sass": "^1.49.10"
  }
}

Which project is this issue for?

@serwist/build

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://projectisprivate-cantreplicate.com

To reproduce

May be harder to reproduce. I had an existing NextJS project and I'm attempting to add serwist for PWA capabilities.

I followed the installation guide for NextJS on the documentation website for all steps.
https://serwist.pages.dev/docs/next/getting-started

I attempted to run the project afterwards with npm run dev and received the error I'm seeing.

Describe the bug

Upon running the project, I get the following error:

$ npm run dev

> [email protected] dev
> next dev

D:\code\roost\node_modules\@serwist\build\dist\index.cjs:65
    glob pattern strings.`,
                           ^

Error [ERR_REQUIRE_ESM]: require() of ES Module D:\code\roost\node_modules\stringify-object\index.js from D:\code\roost\node_modules\@serwist\build\dist\index.cjs not supported.
Instead change the require of index.js in D:\code\roost\node_modules\@serwist\build\dist\index.cjs to a dynamic import() which is available in all CommonJS modules.
    at mod.require (D:\code\roost\node_modules\next\dist\server\require-hook.js:65:28)
    at Object.<anonymous> (D:\code\roost\node_modules\@serwist\build\dist\index.cjs:13:23)
    at mod.require (D:\code\roost\node_modules\next\dist\server\require-hook.js:65:28)
    at Object.<anonymous> (D:\code\roost\node_modules\@serwist\webpack-plugin\dist\index.cjs:3:13)
    at mod.require (D:\code\roost\node_modules\next\dist\server\require-hook.js:65:28)
    at Object.<anonymous> (D:\code\roost\node_modules\@serwist\next\dist\index.cjs:7:21)
    at mod.require (D:\code\roost\node_modules\next\dist\server\require-hook.js:65:28)
    at Object.<anonymous> (D:\code\roost\next.config.js:4:21) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.17.0

Expected behavior

The appropriate modules run, the project builds and is rendered in dev-mode.

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Docs]: Can we have a document about what installSerwist does?

Provide environment information

https://serwist.pages.dev/docs/sw
image

Describe the problem

Currently only click on the > button will expand the submenu. At first, I thought there's no document what so ever after clicking around the doc; took me a while to find the hidden content.

Expected behavior

  1. Click on the side bar menu will pop up the submenu
  2. document for installSerwist is still missing

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

How Can I cache resources from my application to have complete offline feature?

I'm implementing a complete offline application, I dont want to display a fallback page when there is not internet
I want to cache all my files .html, .js, .css, .png, and font families
When there is not internet I want my application check the cache and use it

That set up was posible in an old version of NextJs with next-pwa, but now I'm updating my application and I want to use serwist

Thanks in advance 🙏

[Bug]: Missing `webpack` dependency

Provide environment information

@serwist/next: 8.0.2
@serwist/webpack-plugin: 8.0.2

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

NA

To reproduce

  1. yarn init -y
  2. yarn set version berry
  3. yarn add @serwist/next @serwist/webpack-plugin next react react-dom
  4. See yarn log

Describe the bug

Missing webpack dependency from @serwist/next and @serwist/webpack-plugin

➤ YN0000: · Yarn 4.0.2
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + @serwist/next@npm:8.0.2, @serwist/webpack-plugin@npm:8.0.2, next@npm:14.0.4, and 208 more.
➤ YN0000: └ Completed
➤ YN0000: ┌ Post-resolution validation
➤ YN0002: │ <PROJECT_NAME>@workspace:. doesn't provide webpack (p1fed5), requested by @serwist/next.
➤ YN0002: │ <PROJECT_NAME>@workspace:. doesn't provide webpack (pc79a1), requested by @serwist/webpack-plugin.
➤ YN0086: │ Some peer dependencies are incorrectly met; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code.
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: · Done with warnings

Expected behavior

No warnings in log

Screenshots (if relevant)

No response

Additional information (if relevant)

Workaround:
add in .yarnrc.yml

packageExtensions:
  "@serwist/next@*":
    dependencies:
      webpack: "*"
  "@serwist/webpack-plugin@*":
    dependencies:
      webpack: "*"

[Bug]: Error [ERR_REQUIRE_ESM]: require() of ES Module

Provide environment information

Node.js v20.10.0

dependencies

  • "@serwist/next": "^9.0.0-preview.12",
  • "react": "^18.2.0",

devDependencies

  • "@serwist/core": "^9.0.0-preview.12",
  • "@serwist/precaching": "^9.0.0-preview.12",
  • "@serwist/sw": "^9.0.0-preview.12",

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

To reproduce

const { withSerwistInit } = require("@serwist/next");

Describe the bug

I am using @serwist/next@preview for this project. My next.config.js is works with requires.

Error [ERR_REQUIRE_ESM]: require() of ES Module ./node_modules/@serwist/next/dist/index.js from ./next.config.js not supported.

Instead change the require of index.js in ./next.config.js to a dynamic import() which is available in all CommonJS modules.

at mod.require (./node_modules/next/dist/server/require-hook.js:65:28)
at Object.<anonymous> (./next.config.js:6:29)
at mod.require (./node_modules/next/dist/server/require-hook.js:65:28){
code: 'ERR_REQUIRE_ESM'
}

Expected behavior

Getting withSerwistInit with requiring the package.

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Bug]: Fetch requests do not go through service worker

Provide environment information

"@serwist/next": "^8.4.4",
"@serwist/precaching": "^8.4.3",
"@serwist/sw": "^8.4.3",

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

h

To reproduce

page.tsx:
fetch('/local_test');

sw.ts:
self.addEventListener('fetch', event => {
console.log('Fetching:', event.request.url); // Nothing shown in console (Chromium 121)
}

Describe the bug

Fetch request is not going through service worker (the request does not show up in the console). I also tried 'navigationPreload: false', which did not help. I set the path in public/manifest.json correctly, I think: "start_url": "/PATH_AT_WHICH_PAGE.JSX_IS_SHOWN".

Expected behavior

Fetch request is going through service worker, i.e. the request should be printed in the console.

Screenshots (if relevant)

No response

Additional information (if relevant)

I am trying to create a mock API, therefore using a local URL.

I actually think there are two bugs: I get an error in the console: 'GET https://example.com/local_test' ... net:ERR_FAILED: 1) The URL shown is from an old version of the service worker. It looks like it did not reload, despite 'skipWaiting: true, clientsClaim: true,' 2) I suspect there is an internal serwist fetch listener which is called first, returns a failing promise and then my custom fetch listener is not activated? If so, how can I serve the fetch request anyway?

[Bug]: Logs spammed on console in production

Provide environment information

NextJS 14.1

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://lostark.party/

To reproduce

Created a NextJS app and used the following setting:

import { defaultCache } from "@serwist/next/browser";
import { installSerwist } from "@serwist/sw";

import type { PrecacheEntry } from "@serwist/precaching";

declare const self: ServiceWorkerGlobalScope & {
  // Change this attribute's name to your `injectionPoint`.
  __SW_MANIFEST: (PrecacheEntry | string)[] | undefined;
};

// Anything random.
const revision = crypto.randomUUID();

installSerwist({
  precacheEntries: self.__SW_MANIFEST,
  skipWaiting: true,
  clientsClaim: true,
  navigationPreload: true,
  runtimeCaching: defaultCache,
  disableDevLogs: true,
  fallbacks: {
    entries: [
      {
        url: "/~offline",
        revision,
        matcher({ request }) {
          // Or whatever else you want to check for in a request.
          return request.destination === "document";
        },
      },
    ],
  },
});

Describe the bug

Although disableDevLogs is set to true, on production, the app spams console logs with serwist info

Expected behavior

To not have any logs on production

Screenshots (if relevant)

image

Additional information (if relevant)

Can be viewed on: https://lostark.party

[Docs]: Install/config @serwist/next for PWA

Provide environment information

@serwist/next": "^8.0.0" on Next.js 14.0.4

Describe the problem

Hello,

Thank you for creating this new repo and building this project. I've come accross this post in @next/pwa DuCanhGH/next-pwa#121 where it's recommended to migrate to @serwist/next

I've been wondering how to set up PWA correctly in next.js, I was able to change the config + the sw.ts file. But is that enough? What should I add for the injectionPoint or SW_MANIFEST?

`import { defaultCache } from "@serwist/next/browser";
import type { PrecacheEntry } from "@serwist/precaching";
import { installSerwist } from "@serwist/sw";

declare const self: ServiceWorkerGlobalScope & {
// Change this attribute's name to your injectionPoint.
__SW_MANIFEST: (PrecacheEntry | string)[] | undefined;
};

installSerwist({
precacheEntries: self.__SW_MANIFEST,
skipWaiting: true,
clientsClaim: true,
navigationPreload: true,
runtimeCaching: defaultCache,
});`

Also according to vscode (typescript), it should be ServiceWorkerGlobalScopeEventMapinstead of ServiceWorkerGlobalScope in sw.ts

I'm sorry for my basic questions and I understand you aren't finished with the documentation yet.

Anyways thank you.

Expected behavior

Documentation on setting up PWA in Next.js.

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Bug]: Fast Refresh had to perform a full reload.

Provide environment information

Using next.js 14 and pages router, running npm run dev, following the docs, I get endless loops of refreshs. It says in the node console:

⚠ Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/messages/fast-refresh-reload

It does not happen on the first request, but when I hit CTRL+R once.
Any idea what could be the issue / why it's refreshing the page endlessly?

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

on demand

To reproduce

(I just upgraded from next 13 to 14 to use this lib, I hope that is not the issue, everything else seem to work normally)

Describe the bug

Endless loop of browser reload and the warning (see above)

Expected behavior

No endless refresh loop.

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Bug]: self.addEventListener for "fetch" not working in sw.ts

Provide environment information

@DuCanhGH can reproduce locally

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

@DuCanhGH can reproduce locally

To reproduce

self.addEventListener("fetch", (event: FetchEvent) => {
  console.debug(LOG_TAG, "fetch", event.request.url);
});

// Call this in app/sw.ts
self.addEventListener("message", event => {
  console.debug(LOG_TAG, "message me", { event });
});

I can make the message event fire but not the fetch event

Describe the bug

can't capture fetch

Expected behavior

Should be able to capture fetch

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

`@serwist/next` - additionalPrecacheEntries prevents automatically precaching public dir files

Discussed in #138

Originally posted by jon-smith April 30, 2024
I'm using @serwist/next with a statically exported Next.js app and it's working well, but I'm confused about some precaching options and I'm unsure if it's an issue or I'm using it incorrectly.

I noticed that the index file doesn't get precached by default (I want to ensure this is in sync with the precached js/css files), so I have set up my init as follows:

const withSerwist = withSerwistInit({
	swSrc: 'src/app/sw.ts',
	swDest: 'public/sw.js',
	additionalPrecacheEntries: [{ url: '/', revision }],
});

However this then prevents some files in my public directory from being precached. I noticed in the code (https://github.com/serwist/serwist/blob/main/packages/next/src/index.ts#L165), globPublicPatterns is not used if additionalPrecacheEntries have been set. Is there a reason for this?

The simple workaround is to add my public files to additionalPrecacheEntries but I feel like I might be just using it wrong.

[Bug]: Browser export missing from NextJS package

Provide environment information

Using:

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

Sorry no link, just some screenshots

To reproduce

I've followed all the instructions from https://serwist.pages.dev/docs/next/getting-started including adding the ts typings in my tsconfig.json.

Describe the bug

Hi, I am getting this issue with the defaultCache import on my sw.ts

image

Get the same issue when I run next build.

Upon inspecting /node_modules/@serwist/next/package.json it looks like the browser export is indeed missing:

image

Expected behavior

I expect next build command to run successfully.

Screenshots (if relevant)

image

Additional information (if relevant)

No response

[Bug]: getServerSideProps not triggered

Provide environment information

package versions used:

"@serwist/next": "^8.4.4",
"@serwist/precaching": "^8.4.4",
"@serwist/sw": "^8.4.4",

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

To reproduce

sw.js file:

import { defaultCache } from "@serwist/next/browser";
import { installSerwist } from "@serwist/sw";

// Anything random.
const revision = crypto.randomUUID();

installSerwist({
  // eslint-disable-next-line no-restricted-globals
  precacheEntries: self.__SW_MANIFEST,
  skipWaiting: true,
  clientsClaim: true,
  navigationPreload: true,
  runtimeCaching: defaultCache,
  fallbacks: {
    entries: [
      {
        url: "/offline",
        revision,
        matcher({ request }) {
          return request.destination === "document";
        },
      },
    ],
  },
});

next.config.js

const withSerwist = require("@serwist/next").default({
  cacheOnFrontEndNav: true,
  swSrc: "sw.js",
  swDest: "public/sw.js",
  reloadOnOnline: true,
  disable: process.env.NODE_ENV === "development", // to disable pwa in development
  // ... other options
});

Describe the bug

I recently moved to serwist from next-pwa as i'm slowly going to start migrating to app directory.

While i'm not in app directory yet i noticed that somehow when i do a route change in the browser it seems to pull a fully cached page back and not trigger getServerSideProps anymore and my data comes back empty that i expect to be there.

It's working all fine without service workers involved and with next-pwa this was working properly as well.

If i stay on the page and then actually refresh the browser all the data shows up.

I also tried setting navigationPreloa, clientsClaim and cacheOnFrontEndNav to false without much success.

minimal repo will be tough this seems to also only happen when i run nextjs build. if i enable service worker in local dev environment everything works just fine.

Expected behavior

i expect that my data still comes back from getServerSideProps when a nextjs Link component is clicked.

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Docs]: Getting started page is missing instructions for installing @serwist/precaching and @serwist/sw

Provide environment information

I visited https://serwist.pages.dev/docs/next/getting-started

Describe the problem

At Step 2 - creating sw.ts - VSCode noticed that there are imports for @serwist/precaching and @serwist/sw but I hadn't yet installed those (Step 1 missed them)

Expected behavior

Step 1 should be complete

Screenshots (if relevant)

No response

Additional information (if relevant)

Once I installed those two packages my errors went away

[Docs]: Can I precache routes? (Next)

Provide environment information

Hey, I am new to Service Workers. I try to make my next 14 pwa work fully offline.
Is there a way to prefetch all routes? As far as my testing goes, serwist out of the box only caches already requested routes.

Describe the problem

When I set Network > Throttling > Offline and use a <Link> to an unvisited route, I still leave my app and get hit with a hard Chrome 404. Is this normal?

Expected behavior

I would like to define routes that should be prefetched. If I hit a 404 I would expect to stay in my app and show a message instead of "crashing" it.

Screenshots (if relevant)

Bildschirmfoto 2024-01-22 um 16 15 22

Additional information (if relevant)

No response

[Bug]: Type error: An expression of type 'void' cannot be tested for truthiness.

Provide environment information

Fails in macos m1 sonoma 14.0
Fails also in vercel CI

Which project is this issue for?

None

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

Hard to replicate. but I just followed the docs using a t3 app.

To reproduce

Below is the nextjs config.

const withSerwist = withSerwistInit({
  // Note: This is only an example. If you use Pages Router,
  // use something else that works, such as "service-worker/index.ts".
  cacheOnNavigation: false,
  swSrc: "src/app/sw.ts",
  swDest: "public/sw.js",
  reloadOnOnline: true,
  scope: "/client",
  disable: process.env.NODE_ENV === "development", // to disable pwa in development
})

/** @type {import("next").NextConfig} */
const config = {
  swcMinify: true,

  optimizeFonts: true,
  reactStrictMode: true,
  // typescript: {
  //   ignoreBuildErrors: true,
  // },
  eslint: {
    ignoreDuringBuilds: true,
  },
  images: {
    remotePatterns: [
      {
        protocol: "https",
        hostname: "plus.unsplash.com",
      },
    ],
  },
  experimental: {
    serverComponentsExternalPackages: ["sharp", "onnxruntime-node"],
  },
}



export default withSentryConfig(
  withSerwist(config),
 {....})

This occurs even if it is exported without the sentryconfig


### Describe the bug

./public/sw.js:1:2
Type error: An expression of type 'void' cannot be tested for truthiness.

> 1 | !function(){"use strict";let e,t,a,s,r;let

### Expected behavior

To actually build.

### Screenshots (if relevant)

_No response_

### Additional information (if relevant)

_No response_

[Bug]: require() of ES Module not supported when running tests

Provide environment information

  • Serwist: 8.4.4
  • Next: 14.0.4
  • Node: 20.10.0

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://github.com/hirviid/serwist-next-jest-example

To reproduce

Describe the bug

Running Jest after adding @serwest/next to a nextjs gives an error:

Error [ERR_REQUIRE_ESM]: require() of ES Module ~/serwist-example-next/node_modules/string-width/index.js from ~/serwist-example-next/node_modules/cliui/build/index.cjs not supported.
Instead change the require of index.js in ~/serwist-example-next/node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (~/serwist-example-next/node_modules/cliui/build/index.cjs:291:21)
error Command failed with exit code 1.

Expected behavior

Adding Serwist to a Next project should not impact Jest tests.

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Docs][Bug]: using offline pages

Provide environment information

"@serwist/next": "^8.4.4",
"@serwist/precaching": "^8.4.4",
"@serwist/sw": "^8.4.4",

this is my sw.js

installSerwist({
  cleanupOutdatedCaches: true, 
  precacheEntries: [{url: '/offline', revision: "1"}, ...self?.__SW_MANIFEST??[]],
  skipWaiting: true,
  clientsClaim: true,
  navigationPreload: true,
  disableDevLogs: true,
  runtimeCaching: defaultCache,
  navigateFallback: "/offline",
});

Describe the problem

I wanted to add an offline page in all cases the navigation fallback requires things be preloaded

debuging I noticed that __SW_MANIFEST is undefined during development
so I manually added an entry for the offline page

this worked
except that both in development and during build
if I navigate to the a page using the browser url
I always get the offline page rendered

If I navigate using the navbar available to another page they work

I don't know how to setup offline

Expected behavior

I'm expecting that if I add a navigation fallback that it gets pre-cached in general on it's own
and I'm expecting it to show only when I'm offline

Screenshots (if relevant)

this is working correct I am indeed offline
Screenshot 2024-02-14 at 2 40 22 PM

If I'm online and navigate internally I can see the pages
Screenshot 2024-02-14 at 2 43 47 PM

But if I refresh the request to page is intercepted and offline is rendered, you can see that only that one request fails

Screenshot 2024-02-14 at 2 44 49 PM

Additional information (if relevant)

No response

[Bug]: PPR Forces Load Wait

Provide environment information

OS: MacOS Sonoma
Chip: M3 Pro

Server Runtime: Node 18 LTS
Next Version: 14.1.1-canary.2
Serwist SW & Serwist Next: @latest

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://github.com/versecafe/serwist-ppr-issue-demo

To reproduce

  1. Make a nextJS project with serwist
  2. add PPR and a suspense boundary to main page
  3. set as a PWA
  4. launch PWA

Describe the bug

When using PPR PWA loads until all content is fetched.

Expected behavior

Should load the HTML shell around suspense boundaries and stream in the new content, same as behaviour when visiting the base web version.

Screenshots (if relevant)

image

Additional information (if relevant)

This may just be an issue with PPR or the PWA spec rather than serwist in which case just let me know and I'll remove this.

[Bug]: Snyk vulnerability SNYK-JS-INFLIGHT-6095116

Provide environment information

"@serwist/next": "^9.0.0-preview.6",
"@serwist/precaching": "^9.0.0-preview.6",
"@serwist/sw": "^9.0.0-preview.6",

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

To reproduce

simply install the above packages

Describe the bug

It's not so much a bug perse, but there is a security vulnearbility in inflight that gets included in your package through the clean-webpack-plugin that i saw was being used in @serwist/next here:
https://github.com/serwist/serwist/blob/main/packages/next/src/index.ts#L6
and here:
https://github.com/serwist/serwist/blob/main/packages/next/src/index.ts#L147

is there any chance we can get rid of clean-webpack-plugin and use clean: true in the output as stated in the webpack docs like so:
https://webpack.js.org/guides/output-management/#cleaning-up-the-dist-folder

I know it might not be a big deal, but would clean up some snyk reports.

here is a link to the snyk finding:
https://security.snyk.io/vuln/SNYK-JS-INFLIGHT-6095116

Expected behavior

Nothing is really broken, just trying to do some cleanup

Screenshots (if relevant)

image

Additional information (if relevant)

No response

[Bug]: Import error when trying to use cjs

Provide environment information

@serwist/[email protected]

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://codesandbox.io/p/devbox/eloquent-kate-26hzzz?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clq5cq35i00093b6r2phk3uh3%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clq5cq35h00023b6rt4lzp68k%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clq5cq35h00063b6rwfki12rr%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clq5cq35h00083b6ryjyal06n%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clq5cq35h00023b6rt4lzp68k%2522%253A%257B%2522id%2522%253A%2522clq5cq35h00023b6rt4lzp68k%2522%252C%2522tabs%2522%253A%255B%255D%257D%252C%2522clq5cq35h00083b6ryjyal06n%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clq5cq35h00073b6rdm9bxsyu%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522port%2522%253A3000%252C%2522path%2522%253A%2522%252F%2522%257D%255D%252C%2522id%2522%253A%2522clq5cq35h00083b6ryjyal06n%2522%252C%2522activeTabId%2522%253A%2522clq5cq35h00073b6rdm9bxsyu%2522%257D%252C%2522clq5cq35h00063b6rwfki12rr%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clq5cq35h00033b6rmkg06pgy%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%257D%252C%257B%2522id%2522%253A%2522clq5cq35h00043b6rv4z80cli%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522start%2522%257D%252C%257B%2522id%2522%253A%2522clq5cq35h00053b6rc94ys9ea%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522install%2522%257D%255D%252C%2522id%2522%253A%2522clq5cq35h00063b6rwfki12rr%2522%252C%2522activeTabId%2522%253A%2522clq5cq35h00033b6rmkg06pgy%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

To reproduce

in next.config.js

const withSerwistInit = require("@serwist/next");

const withSerwist = withSerwistInit({
cacheOnFrontEndNav: true,
swSrc: "app/sw.ts",
swDest: "public/sw.js",
});

/** @type {import("next").NextConfig} */
const nextConfig = {
reactStrictMode: true,
};

module.exports = withSerwist(nextConfig);

num run build

Describe the bug

When I am try import cjs like
const withSerwistInit = require("@serwist/next");

I got a error

Error [ERR_REQUIRE_ESM]: require() of ES Module /workspaces/sandbox/node_modules/pretty-bytes/index.js from /workspaces/sandbox/node_modules/@serwist/build/dist/index.old.cjs not supported.
Instead change the require of index.js in /workspaces/sandbox/node_modules/@serwist/build/dist/index.old.cjs to a dynamic import() which is available in all CommonJS modules.

Expected behavior

Regular build

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Bug]: ERR_REQUIRE_ESM with base setup

Provide environment information

    "@serwist/next": "^8.2.0",
    "@serwist/precaching": "^8.2.0",
    "@serwist/sw": "^8.2.0",

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://codesandbox.io/p/devbox/eloquent-kate-26hzzz?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clq5cq35i00093b6r2phk3uh3%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clq5cq35h00023b6rt4lzp68k%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clq5cq35h00063b6rwfki12rr%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clq5cq35h00083b6ryjyal06n%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clq5cq35h00023b6rt4lzp68k%2522%253A%257B%2522id%2522%253A%2522clq5cq35h00023b6rt4lzp68k%2522%252C%2522tabs%2522%253A%255B%255D%257D%252C%2522clq5cq35h00083b6ryjyal06n%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clq5cq35h00073b6rdm9bxsyu%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522port%2522%253A3000%252C%2522path%2522%253A%2522%252F%2522%257D%255D%252C%2522id%2522%253A%2522clq5cq35h00083b6ryjyal06n%2522%252C%2522activeTabId%2522%253A%2522clq5cq35h00073b6rdm9bxsyu%2522%257D%252C%2522clq5cq35h00063b6rwfki12rr%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clq5cq35h00033b6rmkg06pgy%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%257D%252C%257B%2522id%2522%253A%2522clq5cq35h00043b6rv4z80cli%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522start%2522%257D%252C%257B%2522id%2522%253A%2522clq5cq35h00053b6rc94ys9ea%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522install%2522%257D%255D%252C%2522id%2522%253A%2522clq5cq35h00063b6rwfki12rr%2522%252C%2522activeTabId%2522%253A%2522clq5cq35h00033b6rmkg06pgy%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

To reproduce

npm run build following basic instructions

Describe the bug

Doesn't build -

$ npm run build

> build
> next build

 ⨯ Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error

> Build error occurred
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\apsto\dev\website\node_modules\@serwist\webpack-plugin\dist\relative-to-output-path-5MVPPhSi.js from C:\Users\apsto\dev\website\node_modules\@serwist\webpack-plugin\dist\index.cjs not supported.
relative-to-output-path-5MVPPhSi.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename relative-to-output-path-5MVPPhSi.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in C:\Users\apsto\dev\website\node_modules\@serwist\webpack-plugin\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at mod.require (C:\Users\apsto\dev\website\node_modules\next\dist\server\require-hook.js:64:28)
    at Object.<anonymous> (C:\Users\apsto\dev\website\node_modules\@serwist\webpack-plugin\dist\index.cjs:8:28) {
  code: 'ERR_REQUIRE_ESM'

Expected behavior

Build succeeds

Screenshots (if relevant)

No response

Additional information (if relevant)

8.04 Seems to build fine

[Bug]: Next pages navigation causes stale data

Provide environment information

  • @serwist/next

Which project is this issue for?

None

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

To reproduce

  • Navigate over a nextjs project but have the pages revalidate in the background.

Describe the bug

A regular page loads as it is using this configuration: https://github.com/serwist/serwist/blob/main/packages/next/src/index.browser.ts#L188-L198

But you get old data when using the 'ajax call':
https://github.com/serwist/serwist/blob/main/packages/next/src/index.browser.ts#L117-L127

Expected behavior

We've currently set it to NetworkFirst to handle this case, that solves the issue.

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

[Bug]: serwist/next using `basePath` results in wrong sw.js URL in manifest

Provide environment information

"@serwist/next": "^8.4.3",
"@serwist/precaching": "^8.4.3",
"@serwist/sw": "^8.4.3",
"next": "^14.1.0",

Next.JS is using the app router and source is in app/src

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://github.com/msanguineti/next-pwa-test

To reproduce

  • add output: 'export' to next.config options
  • add basePath to next.config options
  • run npm run build to get static files for a website under out/
  • check the injected precache manifest found in out/sw.js

Describe the bug

The URL for the service worker (default sw.js) is wrongly injected in the manifest, an extra _next/../public/ path is found there:

...
precacheEntries: [
    {
      revision: "71782f0a19e1ac2b7126fa129afe790b",
      url: "/next-pwa-test/_next/../public/sw.js",
    },
   ...
]
...

Expected behavior

This is what I should expect:

...
precacheEntries: [
    {
      revision: "71782f0a19e1ac2b7126fa129afe790b",
      url: "/next-pwa-test/sw.js",
    },
   ...
]
...

Screenshots (if relevant)

No response

Additional information (if relevant)

If I don't use basePath, the plugin correctly inject the service worker path.

I found this in the source code:

modifyURLPrefix: {
...modifyURLPrefix,
"/_next/../public/": "/",
},

This is probably done to remove the extra fluff path /_next/../public/ generated. But when using basePath this substitution does not match and the extra path is not removed.

I also tried to use swUrl but it has no effect whatsoever, even setting swUrl to something crazy:

...
swDest: "public/sw.js"
swUrl: "in/the/middle/of/nowhere/unserviceable-worker.js"
...

nothing happens, the service worker is always injected at [basePath]/_next/../public/sw.js

To solve the issue I resorted to use manifest transformations in next.config.js:

/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'export',
  basePath: '/next-pwa-test',
}


/** @type {import("@serwist/build").ManifestTransform}  */
const manifestTransforms = async (manifestEntries) => {
  const manifest = manifestEntries.map((m) => {
    m.url = m.url.replace("/_next/../public/", "/");
    return m;
  });
  return { manifest, warnings: [] };
}

/** @type {import("@serwist/next")} */
const withSerwist = require("@serwist/next").default({
  swSrc: "src/app/sw.ts",
  swDest: "public/sw.js",
  manifestTransforms: [manifestTransforms],
});

module.exports = withSerwist({
  ...nextConfig,
});

[Bug]: serwist tries to install service worker with different name than specified in next config

Provide environment information

"@serwist/next": "^8.4.4",
"@serwist/precaching": "^8.4.4",
"@serwist/sw": "^8.4.4",

I also have such next.js config

import withPWAInit from '@serwist/next'

/** @type {import('next').NextConfig} */
const withPWA = withPWAInit({
    swSrc: 'app/service-worker.ts',
    swDest: 'public/service-worker.js',
})

const nextConfig = { output: 'standalone' }

export default withPWA(nextConfig)

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://github.com/mturczyn/about-intrinsic-nextjs/blob/main/next.config.mjs

To reproduce

Setup next.js project with serwist and use service-worker.js as destination file.

Describe the bug

I expect for it to work seamlesly, however I keep getting following error in browser:

DOMException: Failed to register a ServiceWorker for scope ('http://localhost:3000/') with script ('http://localhost:3000/sw.js'): The script has an unsupported MIME type ('text/html').

As shown, it still tries to get sw.js file.

However, service worker JavaScript file was correctly generated in public directory.

After just changing swDest: 'public/service-worker.js' to swDest: 'public/sw.js' solved the issue:

image

Also, I have noticed, when I changed swDest file name, previously generated JS file was not removed and I guess, as "compilation"/parsing output, it should be cleaned automatically.

Expected behavior

I can specify whatever file name for service worker and all should be wired up by serwist

I can freely change name of service worker in next.js config file, and not keep all previous files with different file names - if i change name for service worker file, somehow old file should be cleaned.

Screenshots (if relevant)

Successfull service worker installation

image

Additional information (if relevant)

No response

[Bug]: Ui of the website has issues

Provide environment information

There is a width:100vw defined that is causing this issue; please fix that.

Which project is this issue for?

None

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://serwist.pages.dev/

To reproduce

Visit the website

Describe the bug

width:100vw

Expected behavior

remove this width

Screenshots (if relevant)

image

Remove this width:100vw
image

Additional information (if relevant)

No response

[Bug]: Self is not defined

Provide environment information

{
  "name": "roost",
  "version": "0.2.1",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^6.2.0",
    "@fortawesome/free-brands-svg-icons": "^6.2.0",
    "@fortawesome/free-regular-svg-icons": "^6.2.0",
    "@fortawesome/free-solid-svg-icons": "^6.2.0",
    "@fortawesome/react-fontawesome": "^0.2.0",
    "@serwist/next": "^8.4.1",
    "@serwist/precaching": "^8.4.1",
    "@serwist/sw": "^8.4.1",
    "isomorphic-unfetch": "^3.1.0",
    "js-cookie": "^3.0.1",
    "luxon": "^3.3.0",
    "moment": "^2.29.4",
    "next": "^14.0.4",
    "next-cookies": "^2.0.3",
    "normalize.css": "^8.0.1",
    "npm": "^10.2.5",
    "octokit": "^3.1.2",
    "prisma": "^5.7.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-hot-toast": "^2.4.0",
    "react-image-gallery": "^1.2.11",
    "react-modal": "^3.16.1",
    "react-tabs": "^5.1.0",
    "react-twemoji": "^0.5.0",
    "rss-parser": "^3.13.0",
    "snoowrap": "^1.23.0"
  },
  "devDependencies": {
    "eslint": "^8.56.0",
    "eslint-config-next": "^14.0.4",
    "sass": "^1.49.10"
  }
}

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

import { defaultCache } from "@serwist/next/browser";
import { installSerwist } from "@serwist/sw";

installSerwist({
  precacheEntries: self.__SW_MANIFEST,
  skipWaiting: true,
  clientsClaim: true,
  navigationPreload: true,
  runtimeCaching: defaultCache,
});

Describe the bug

✓ 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

[Feature request]: nuxt package?

Which project is this feature request for?

None

Describe the feature you'd like to request

Since there’s a next package, is there a item on the roadmap to enable this to be used with Vite & Nuxt?

Describe the solution you'd like

Use it as a Nuxt module

Describe alternatives you've considered

@kevinmarrec has nuxt pwa which I’ve used before

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.