vuejs/vue · error · Error
Invalid JSON bundle file: ${bundle}
Error message
Invalid JSON bundle file: ${bundle} What it means
Thrown by createBundleRenderer when an absolute .json bundle path is read from disk but JSON.parse fails. The bundle argument was reassigned to the raw file contents before parsing, so the error message shows the (potentially large) raw string rather than the path. This indicates the JSON manifest produced by vue-ssr-webpack-plugin or a custom pipeline is corrupt or not valid JSON.
Source
Thrown at packages/server-renderer/src/bundle-renderer/create-bundle-renderer.ts:57
let files, entry, maps
let basedir = rendererOptions.basedir
// load bundle if given filepath
if (
typeof bundle === 'string' &&
/\.js(on)?$/.test(bundle) &&
path.isAbsolute(bundle)
) {
if (fs.existsSync(bundle)) {
const isJSON = /\.json$/.test(bundle)
basedir = basedir || path.dirname(bundle)
bundle = fs.readFileSync(bundle, 'utf-8')
if (isJSON) {
try {
// @ts-expect-error
bundle = JSON.parse(bundle)
} catch (e: any) {
throw new Error(`Invalid JSON bundle file: ${bundle}`)
}
}
} else {
throw new Error(`Cannot locate bundle file: ${bundle}`)
}
}
if (typeof bundle === 'object') {
entry = bundle.entry
files = bundle.files
basedir = basedir || bundle.basedir
maps = createSourceMapConsumers(bundle.maps)
if (typeof entry !== 'string' || typeof files !== 'object') {
throw new Error(INVALID_MSG)
}
} else if (typeof bundle === 'string') {
entry = '__vue_ssr_bundle__'
files = { __vue_ssr_bundle__: bundle }View on GitHub (pinned to 9e88707940)
Solutions
- Regenerate the bundle manifest by re-running the webpack SSR build with VueSSRServerPlugin.
- Validate the file with `node -e "JSON.parse(require('fs').readFileSync('path','utf-8'))"` to confirm it is parseable.
- If the file is a raw JS bundle (single file), pass it with a .js extension instead of .json, or pass the manifest object directly.
- Check for truncation: compare file size against a known-good build or re-emit from a clean build directory.
Example fix
// before — file is corrupt/truncated JSON
createBundleRenderer('/app/dist/vue-ssr-server-bundle.json')
// after — regenerate manifest then load, or load object directly
const bundle = require('/app/dist/vue-ssr-server-bundle.json')
createBundleRenderer(bundle) Defensive patterns
Strategy: validation
Validate before calling
import * as fs from 'fs'
function isValidJsonBundle(path: string): boolean {
if (!fs.existsSync(path)) return false
try {
const obj = JSON.parse(fs.readFileSync(path, 'utf-8'))
return typeof obj === 'object' && obj !== null && typeof obj.entry === 'string'
} catch {
return false
}
}
if (!isValidJsonBundle(bundlePath)) {
throw new Error(`${bundlePath} is not a valid SSR bundle JSON; rebuild it.`)
}
createBundleRenderer(bundlePath) Type guard
function isRenderBundle(v: unknown): v is { entry: string; files: Record<string,string>; maps?: Record<string,string> } {
if (typeof v !== 'object' || v === null) return false
const o = v as any
return typeof o.entry === 'string' && typeof o.files === 'object'
} Try / catch
try {
createBundleRenderer(bundlePath)
} catch (e) {
if (e.message.startsWith('Invalid JSON bundle file')) {
// delete corrupt artifact and trigger rebuild
fs.unlinkSync(bundlePath)
await rebuildSSRBundle()
}
throw e
} Prevention
- Never hand-edit generated SSR bundle manifests.
- In CI, fail the build if the manifest JSON cannot be parsed after emission.
- Treat the manifest as a build artifact: regenerate from source rather than mutating on disk.
- Write manifests atomically (temp file + rename) to avoid truncation on killed builds.
When it happens
Trigger: Calling createBundleRenderer('/abs/path/to/vue-ssr-server-bundle.json') where the file exists but is malformed JSON — truncated, contains BOM, has trailing commas, was partially written, or is actually a JS bundle mislabeled .json.
Common situations: A build job was killed mid-write leaving a truncated JSON file. A CI cache served a stale/corrupt manifest. The .json extension was mistakenly applied to a raw JS bundle string. Manual edits to the generated manifest introduced invalid syntax.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Cannot locate bundle file: ${bundle}
- Invalid server-rendering bundle format. Should be a string o
- renderer cache must implement at least get & set.
- [@vue/compiler-sfc] SFC contains no <script> tags.
- \n\nVue packages version mismatch:\n\n- vue@${vueVersion}\n-
AI-assisted analysis of vuejs/vue@9e88707940 (2026-08-11).
Data as JSON: /api/errors/92744786e5179378.
Report an issue: GitHub.