Skip to content

[injectManifest] Error during build: The 'swSrc' file can't be read. ENOENT: no such file or directory #101

@bravier

Description

@bravier

Continuation of #100.

It looks like installing workbox-window is needed when using injectManifest strategy otherwise the build command crashes with:

error during build:
[vite-plugin-pwa:sveltekit:build] The 'swSrc' file can't be read. ENOENT: no such file or directory, open '/tmp/vite-pwa-inject-manifest-swSrc-no-such-file-or-directory/.svelte-kit/output/client/service-worker.js'
    at injectManifest (/tmp/vite-pwa-inject-manifest-swSrc-no-such-file-or-directory/node_modules/.pnpm/[email protected]/node_modules/workbox-build/build/inject-manifest.js:70:15)
    at async Object.handler (file:///tmp/vite-pwa-inject-manifest-swSrc-no-such-file-or-directory/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_svelt_393a97f75c9db1dc5edf7c99a890c00e/node_modules/@vite-pwa/sveltekit/dist/index.mjs:266:33)
    at async PluginDriver.hookParallel (file:///tmp/vite-pwa-inject-manifest-swSrc-no-such-file-or-directory/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:21813:17)
    at async file:///tmp/vite-pwa-inject-manifest-swSrc-no-such-file-or-directory/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:22796:13
    at async catchUnfinishedHookActions (file:///tmp/vite-pwa-inject-manifest-swSrc-no-such-file-or-directory/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:22243:16)
    at async rollupInternal (file:///tmp/vite-pwa-inject-manifest-swSrc-no-such-file-or-directory/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:22772:5)
    at async buildEnvironment (file:///tmp/vite-pwa-inject-manifest-swSrc-no-such-file-or-directory/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/dep-B0fRCRkQ.js:51463:14)
    at async Object.defaultBuildApp [as buildApp] (file:///tmp/vite-pwa-inject-manifest-swSrc-no-such-file-or-directory/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/dep-B0fRCRkQ.js:51926:5)
    at async CAC.<anonymous> (file:///tmp/vite-pwa-inject-manifest-swSrc-no-such-file-or-directory/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite/dist/node/cli.js:860:7)

Minimal reproduction: https://github.com/bravier/vite-pwa-inject-manifest-swSrc-no-such-file-or-directory

  1. git clone https://github.com/bravier/vite-pwa-inject-manifest-swSrc-no-such-file-or-directory
  2. pnpm install
  3. pnpm buildThe 'swSrc' file can't be read. ENOENT: no such file or directory, open '.svelte-kit/output/client/service-worker.js'
  4. pnpm install -D workbox-window
  5. pnpm build → no errors, everything is fine

Or when using pnpm create @vite-pwa/pwa:

pnpm create @vite-pwa/pwa
✔ Project name: … vite-project
✔ Select a framework: › Svelte
✔ Select a variant: › SvelteKit ↗
✔ PWA Name: … vite-project
✔ PWA Short Name: … vite-project
✔ PWA Description: … 
✔ Theme color: … #ffffff
✔ Select a strategy: › injectManifest
✔ Select a behavior: › Prompt for update
✔ Enable periodic SW updates? … no / yes
✔ Show offline ready prompt? … no / yes
✔ Generate PWA Assets Icons on the fly? … no / yes
┌  Welcome to the Svelte CLI! (v0.6.26)
│
◇  Which template would you like?
│  SvelteKit minimal
│
◇  Add type checking with TypeScript?
│  Yes, using TypeScript syntax
│
◆  Project created
│
◇  What would you like to add to your project? (use arrow keys / space bar)
│  none
│
◇  Which package manager do you want to install dependencies with?
│  pnpm
│
◆  Successfully installed dependencies

cd vite-project

pnpm install → workbox-window is explicitly installed here so the build works fine

pnpm build → ok

pnpm remove workbox-window

pnpm build → error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions