vuejs/core · error · Error
enum cache needs to be initialized before creating plugin
Error message
enum cache needs to be initialized before creating plugin
What it means
Thrown by inlineEnums() in Vue's internal build script (scripts/inline-enums.js). The plugin reads an enum cache file (ENUM_CACHE_PATH) that a prior build phase must write; if it does not exist, line 221 throws. This is build-tooling plumbing for inlining const enums during the Vue release build, not user-facing runtime code.
Source
Thrown at scripts/inline-enums.js:221
/** @type {EnumData} */
const enumData = {
declarations,
defines,
}
writeFileSync(ENUM_CACHE_PATH, JSON.stringify(enumData))
return () => {
rmSync(ENUM_CACHE_PATH, { force: true })
}
}
/**
* @returns {[import('rollup').Plugin, Record<string, string>]}
*/
export function inlineEnums() {
if (!existsSync(ENUM_CACHE_PATH)) {
throw new Error('enum cache needs to be initialized before creating plugin')
}
/**
* @type {EnumData}
*/
const enumData = JSON.parse(readFileSync(ENUM_CACHE_PATH, 'utf-8'))
// 3. during transform:
// 3.1 files w/ enum declaration: rewrite declaration as object literal
// 3.2 files using enum: inject into esbuild define
/**
* @type {import('rollup').Plugin}
*/
const plugin = {
name: 'inline-enum',
transform(code, id) {
/**
* @type {MagicString | undefined}
*/View on GitHub (pinned to a2b40db9a8)
Solutions
- Run the cache-initialization phase (the function that writes ENUM_CACHE_PATH) before instantiating the inlineEnums plugin.
- Follow the canonical build order in scripts/build.js / rollup config so prepare runs first.
- If the cache was removed mid-build, re-run the full build rather than reusing a stale rollup invocation.
- Only Vue release maintainers should hit this — verify you are running the documented build entry point.
Example fix
// before const plugin = inlineEnums() // cache not yet written // after const cleanup = prepareAndWriteEnumCache() const plugin = inlineEnums() // cache exists now // ... later: cleanup()
Defensive patterns
Strategy: validation
Validate before calling
// (Vue release maintainers only) ensure the cache exists before inlineEnums().
import { existsSync } from 'fs'
function safeInlineEnums() {
if (!existsSync(ENUM_CACHE_PATH)) {
throw new Error('Run the enum-cache prepare step before inlineEnums()')
}
return inlineEnums()
} Type guard
function enumCacheReady(): boolean {
return existsSync(ENUM_CACHE_PATH)
} Prevention
- Run the full Vue release build pipeline in order; do not instantiate inlineEnums() before the prepare phase.
- If the cleanup callback ran mid-build, start a fresh build instead of reusing the pipeline.
- Only Vue maintainers should touch this; use the documented build entry points.
When it happens
Trigger: Calling inlineEnums() before the cache-generating phase (the prepare/extract step that writes ENUM_CACHE_PATH via writeFileSync). Running only part of the Vue release build pipeline; invoking the rollup config out of order.
Common situations: Editing the Vue release scripts and reordering plugins; running a partial build locally; the cleanup callback (rmSync of the cache) running before a second plugin instance is created.
Related errors
- Found the following treeshaking errors:\n\n- ${errors.join('
- invalid target version: ${targetVersion}
- CI for the latest commit has not passed yet. Only run the re
- [@vue/compiler-core] decodeEntities option is required in br
- [@vue/compiler-sfc] <script> and <script setup> must have th
AI-assisted analysis of vuejs/core@a2b40db9a8 (2026-08-12).
Data as JSON: /api/errors/c84d8ef05b4e3a34.
Report an issue: GitHub.