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

  1. Regenerate the bundle manifest by re-running the webpack SSR build with VueSSRServerPlugin.
  2. Validate the file with `node -e "JSON.parse(require('fs').readFileSync('path','utf-8'))"` to confirm it is parseable.
  3. 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.
  4. 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

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

Related errors


AI-assisted analysis of vuejs/vue@9e88707940 (2026-08-11). Data as JSON: /api/errors/92744786e5179378. Report an issue: GitHub.