{"record":{"id":"e753bbb91da3a3ed","repo":"oven-sh/bun","slug":"virtual-css-module-not-found-path","errorCode":null,"errorMessage":"Virtual CSS module not found: ${path}","messagePattern":"Virtual CSS module not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bun-plugin-svelte/src/index.ts","lineNumber":129,"sourceCode":"\n          // NOTE: we assume js/ts modules won't have CSS blocks in them, so no\n          // virtual modules get created.\n          return {\n            contents: result.js.code,\n            loader: \"js\",\n          };\n        })\n        .onResolve({ filter: /^bun-svelte:/ }, args => {\n          return {\n            path: args.path,\n            namespace: \"bun-svelte\",\n          };\n        })\n        .onLoad({ filter: /\\.css$/, namespace: virtualNamespace }, args => {\n          const { path } = args;\n\n          const mod = virtualCssModules.get(path);\n          if (!mod) throw new Error(\"Virtual CSS module not found: \" + path);\n          const { sourcePath, source } = mod;\n          virtualCssModules.delete(path);\n\n          return {\n            contents: source,\n            loader: \"css\",\n            watchFiles: [sourcePath],\n          };\n        });\n    },\n  };\n}\n\nexport default SveltePlugin({ development: true }) as BunPlugin;\nexport { SveltePlugin, type SvelteOptions };\n","sourceCodeStart":111,"sourceCodeEnd":145,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/packages/bun-plugin-svelte/src/index.ts#L111-L145","documentation":"The Bun Svelte plugin stashes CSS extracted from .svelte files in a virtualCssModules map keyed by path, then serves (and deletes) each entry the first time the bundler loads it in the 'bun-svelte' virtual namespace. If the bundler requests a virtual CSS path with no entry — already consumed, or registered by a different plugin instance — onLoad throws this error.","triggerScenarios":"Reusing one Bun.svelte() plugin instance across two concurrent builds (entries consumed by the first build are gone for the second); watch-mode rebuilds requesting a stale virtual path; two copies of the plugin (duplicate installs) splitting registrations and loads.","commonSituations":"Build scripts that hoist a single plugin instance and call Bun.build twice (e.g. client + server bundles in parallel); monorepos where bun-plugin-svelte appears twice in node_modules; HMR rebuilds racing the map deletion.","solutions":["Create a fresh Bun.svelte() instance per build call instead of sharing one","Run the concurrent builds sequentially if instances cannot be isolated","Dedupe bun-plugin-svelte to a single copy (check overrides/lockfile)","Do a clean rebuild to clear stale virtual path references"],"exampleFix":"// before\nconst plugin = Bun.svelte(); // one shared instance\nawait Promise.all([Bun.build({ plugins: [plugin] }), Bun.build({ plugins: [plugin] })]);\n\n// after\nawait Promise.all([\n  Bun.build({ plugins: [Bun.svelte()] }), // fresh instance per build\n  Bun.build({ plugins: [Bun.svelte()] }),\n]);","handlingStrategy":"try-catch","validationCode":"const cssPlugin = Bun.svelte();\n// do not share this instance across builds; instantiate per build call\nconst plugins = () => [Bun.svelte()];","typeGuard":null,"tryCatchPattern":"try {\n  await Bun.build({ entrypoints: [entry], plugins: [Bun.svelte()] });\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Virtual CSS module not found')) {\n    // stale/consumed virtual module: rebuild with a fresh plugin instance\n    await Bun.build({ entrypoints: [entry], plugins: [Bun.svelte()] });\n  } else throw err;\n}","preventionTips":["Never hoist a single Bun.svelte() instance across concurrent builds","Dedupe bun-plugin-svelte in the lockfile","Instantiate plugins inside the build function, not at module scope"],"tags":["svelte","plugin","css","bundler"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}