{"record":{"id":"c3b838f77edda9ce","repo":"vuejs/vue","slug":"cannot-locate-bundle-file-bundle","errorCode":null,"errorMessage":"Cannot locate bundle file: ${bundle}","messagePattern":"Cannot locate bundle file: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server-renderer/src/bundle-renderer/create-bundle-renderer.ts","lineNumber":61,"sourceCode":"    if (\n      typeof bundle === 'string' &&\n      /\\.js(on)?$/.test(bundle) &&\n      path.isAbsolute(bundle)\n    ) {\n      if (fs.existsSync(bundle)) {\n        const isJSON = /\\.json$/.test(bundle)\n        basedir = basedir || path.dirname(bundle)\n        bundle = fs.readFileSync(bundle, 'utf-8')\n        if (isJSON) {\n          try {\n            // @ts-expect-error\n            bundle = JSON.parse(bundle)\n          } catch (e: any) {\n            throw new Error(`Invalid JSON bundle file: ${bundle}`)\n          }\n        }\n      } else {\n        throw new Error(`Cannot locate bundle file: ${bundle}`)\n      }\n    }\n\n    if (typeof bundle === 'object') {\n      entry = bundle.entry\n      files = bundle.files\n      basedir = basedir || bundle.basedir\n      maps = createSourceMapConsumers(bundle.maps)\n      if (typeof entry !== 'string' || typeof files !== 'object') {\n        throw new Error(INVALID_MSG)\n      }\n    } else if (typeof bundle === 'string') {\n      entry = '__vue_ssr_bundle__'\n      files = { __vue_ssr_bundle__: bundle }\n      maps = {}\n    } else {\n      throw new Error(INVALID_MSG)\n    }","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/vuejs/vue/blob/9e88707940088cb1f4cd7dd210c9168a50dc347c/packages/server-renderer/src/bundle-renderer/create-bundle-renderer.ts#L43-L79","documentation":"Thrown by createBundleRenderer when the bundle argument is an absolute path ending in .js or .json but fs.existsSync returns false. The path was deemed a file path (absolute, correct extension) but no file lives there. Distinguish from error 4 which fires only when the file exists but is unreadable/invalid.","triggerScenarios":"Calling createBundleRenderer with a path that is absolute and ends in .js/.json but does not exist on disk. Typical when the build output directory moved, the filename changed, or a relative path was incorrectly absolutized.","commonSituations":"Deployment to a server where the bundle path differs from the build machine. A typo in the path. Build artifacts were cleaned/deleted before the render server started. Using path.join with wrong base dir produces a plausible-looking but nonexistent absolute path.","solutions":["Verify the path exists before calling createBundleRenderer: assert fs.existsSync(bundlePath).","Rebuild the SSR bundle to regenerate the file at the expected location.","If the bundle is in memory (object), pass the object directly instead of a file path.","Log the resolved absolute path and confirm it matches the actual build output."],"exampleFix":"// before\nconst renderer = createBundleRenderer(path.join(__dirname, 'bundle.json'))\n\n// after\nconst bundlePath = path.join(__dirname, 'bundle.json')\nif (!fs.existsSync(bundlePath)) {\n  throw new Error(`SSR bundle not found at ${bundlePath}; run the build first`)\n}\nconst renderer = createBundleRenderer(bundlePath)","handlingStrategy":"validation","validationCode":"import * as fs from 'fs'\nimport * as path from 'path'\n\nfunction assertBundleExists(p: string): void {\n  if (!path.isAbsolute(p)) throw new Error(`Bundle path must be absolute: ${p}`)\n  if (!fs.existsSync(p)) throw new Error(`Bundle file not found: ${p}. Run the SSR build.`)\n}\n\nassertBundleExists(bundlePath)\ncreateBundleRenderer(bundlePath)","typeGuard":"function isExistingBundlePath(p: string): boolean {\n  return typeof p === 'string' && path.isAbsolute(p) && /\\.js(on)?$/.test(p) && fs.existsSync(p)\n}","tryCatchPattern":"try {\n  createBundleRenderer(bundlePath)\n} catch (e) {\n  if (e.message.startsWith('Cannot locate bundle file')) {\n    // trigger build, then retry once\n    await buildSSRBundle()\n    createBundleRenderer(bundlePath)\n  } else {\n    throw e\n  }\n}","preventionTips":["Validate the bundle path in your server's startup config check before SSR init.","Use a health-check endpoint that confirms the bundle exists before accepting traffic.","Store the build output path in a single config constant reused by build and server.","In Docker/CI, assert the bundle file exists as a final build step."],"tags":["ssr","bundle-renderer","filesystem","path","validation"],"analyzedSha":"9e88707940088cb1f4cd7dd210c9168a50dc347c","analyzedAt":"2026-08-11T22:22:01.295Z","schemaVersion":2},"datasetVersion":"2026-08-12T04:17:13.124Z"}