{"record":{"id":"a28568b234d0d5ad","repo":"slidevjs/slidev","slug":"slidev-failed-to-load-pwa-package-which-is","errorCode":null,"errorMessage":"[slidev] Failed to load \"${PWA_PACKAGE}\", which is required by the \"pwa\" option.","messagePattern":"\\[slidev\\] Failed to load \"(.+?)\", which is required by the \"pwa\" option\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slidev/node/vite/pwa.ts","lineNumber":64,"sourceCode":"  })\n}\n\n/**\n * Resolve `vite-plugin-pwa`'s `VitePWA` factory, prompting the user to install\n * the optional peer dependency when the `pwa` option is enabled but the package\n * is missing.\n */\nasync function resolveVitePWA(): Promise<VitePWAFn> {\n  let mod = await importOptionalDependency<{ VitePWA?: VitePWAFn, default?: { VitePWA?: VitePWAFn } }>(PWA_PACKAGE)\n\n  if (!mod?.VitePWA && !mod?.default?.VitePWA) {\n    await promptForOptionalInstallation(PWA_PACKAGE, 'The \"pwa\" option')\n    mod = await importOptionalDependency(PWA_PACKAGE)\n  }\n\n  const VitePWA = mod?.VitePWA ?? mod?.default?.VitePWA\n  if (!VitePWA)\n    throw new Error(`[slidev] Failed to load \"${PWA_PACKAGE}\", which is required by the \"pwa\" option.`)\n\n  return VitePWA\n}\n\n/**\n * When PWA is disabled, resolve `virtual:pwa-register` to a no-op module. The\n * client only imports it behind the `__SLIDEV_FEATURE_PWA__` guard (stripped\n * from the build when off), but the guarded dynamic import must still resolve\n * during dev — without pulling in the optional `vite-plugin-pwa` dependency.\n */\nfunction createPWARegisterStubPlugin(): Plugin {\n  const VIRTUAL_ID = 'virtual:pwa-register'\n  const RESOLVED_ID = `\\0${VIRTUAL_ID}`\n  return {\n    name: 'slidev:pwa-register-stub',\n    resolveId(id) {\n      return id === VIRTUAL_ID ? RESOLVED_ID : undefined\n    },","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/slidevjs/slidev/blob/0d798ace5828966d9f77f62094d5f7a971ad98f7/packages/slidev/node/vite/pwa.ts#L46-L82","documentation":"Thrown by `resolveVitePWA` when Slidev's `pwa` option is enabled (per `options.data.config.pwa`) but `vite-plugin-pwa` cannot be loaded. The resolver first does an optional import, then prompts the user to install it, then retries; only if the factory `VitePWA` is still missing after both attempts does it throw. Note: when PWA is disabled (the default), Slidev never reaches this code — it returns a stub plugin instead, so this error is strictly opt-in.","triggerScenarios":"`pwa: true` (or matching mode) set in `slidev.config.ts` / headmatter while `vite-plugin-pwa` is not installed, and the interactive install prompt was declined, skipped (non-TTY/CI), or failed. Also fires if the package is installed but exports neither a named `VitePWA` nor a `default.VitePWA` (incompatible/corrupt version).","commonSituations":"Enabling `pwa: true` without installing the optional peer dependency; running Slidev in CI/Docker where `promptForOptionalInstallation` cannot get user input and the install silently no-ops; upgrading `vite-plugin-pwa` to a version that changed its export shape; a partially-installed/corrupt node_modules where the package directory exists but the entry file fails to load.","solutions":["Install the optional dependency: `npm i vite-plugin-pwa` (or pnpm/yarn equivalent), then restart.","If you did not intend to ship a PWA, disable the option — set `pwa: false` or remove the `pwa` key from your Slidev config / frontmatter `defaults`.","If installed but still failing, verify the package version exports `VitePWA` (named or via `default`); downgrade/upgrade to a compatible release and clear `node_modules`.","In non-interactive environments (CI, containers), pre-install `vite-plugin-pwa` before launching the dev/build so the prompt fallback is never relied upon."],"exampleFix":"// before: headmatter enables pwa without the dep installed\n---\npwa: true\n---\n// after (option A): install the dependency\n//   npm i vite-plugin-pwa\n// after (option B): turn the feature off\n---\npwa: false\n---","handlingStrategy":"validation","validationCode":"// Before enabling pwa, confirm the optional dependency is importable:\nasync function canLoadVitePWA(): Promise<boolean> {\n  try {\n    const mod = await import('vite-plugin-pwa')\n    return Boolean(mod.VitePWA ?? mod.default?.VitePWA)\n  } catch {\n    return false\n  }\n}\n// only set pwa: true when this returns true (or install it first).","typeGuard":"import type VitePWAFactory from 'vite-plugin-pwa'\nfunction isVitePWAFn(x: unknown): x is (opts: Record<string, any>) => unknown {\n  return typeof x === 'function'\n}","tryCatchPattern":"// Wrap your config build in CI so a missing PWA dep degrades gracefully:\ntry {\n  await build({ pwa: true })\n} catch (e) {\n  if (String(e.message).includes('vite-plugin-pwa')) {\n    console.warn('PWA disabled: vite-plugin-pwa missing. Building without PWA.')\n    await build({ pwa: false })\n  } else throw e\n}","preventionTips":["Treat `pwa: true` as requiring `vite-plugin-pwa`; install it whenever you enable the option.","In CI/Docker, pre-install `vite-plugin-pwa` since the interactive install prompt cannot run headless.","After upgrading `vite-plugin-pwa`, confirm it still exports `VitePWA` (named or `default`).","If PWA is optional for your use case, leave the option off (the default) — Slidev then needs no extra dependency."],"tags":["slidev","pwa","optional-dependency","peer-dependency","config"],"backgroundTag":null,"analyzedSha":"0d798ace5828966d9f77f62094d5f7a971ad98f7","analyzedAt":"2026-08-12T17:10:56.221Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}