vitejs/vite · error · Error

Either "build.lib.entry" or the top-level "input" option is…

Error message

Either "build.lib.entry" or the top-level "input" option is required when "build.lib" is set.

What it means

In `resolveRolldownOptions`, when `build.lib` is set the code requires `libOptions.entry` to be defined. If `entry` is null/undefined and there is no fallback, the build cannot know what to bundle as the library entry, so it throws instructing you to set either `build.lib.entry` or the top-level `input`.

Solutions

  1. Add `entry` to `build.lib`: `build: { lib: { entry: 'src/index.ts', name: 'MyLib', formats: ['es'] } }`.
  2. Alternatively set a top-level `build.rollupOptions.input` (the `input` option) when `build.lib` is set.
  3. Double-check spelling - it's `entry`, not `entries`/`entires`.

Example fix

// before
build: { lib: { name: 'MyLib', formats: ['es', 'umd'] } }
// after
build: { lib: { entry: 'src/index.ts', name: 'MyLib', formats: ['es', 'umd'] } }
Defensive patterns

Strategy: validation

Validate before calling

function assertLibEntryPresent(cfg: { build?: { lib?: { entry?: unknown } }; rollupOptions?: { input?: unknown } }) {
  const lib = cfg.build?.lib
  if (lib && lib.entry == null && cfg.rollupOptions?.input == null) {
    throw new Error('build.lib is set but build.lib.entry and top-level input are missing')
  }
}

Type guard

function libConfigHasEntry(cfg: any): boolean {
  return !cfg?.build?.lib || cfg.build.lib.entry != null || cfg?.rollupOptions?.input != null
}

Prevention

When it happens

Trigger: Configuring `build: { lib: { name: 'MyLib', formats: ['es'] } }` without an `entry` field and without a top-level `input` option, then running `vite build`.

Common situations: Incomplete library config copied from docs where `entry` was omitted. Building `lib` from a flag that conditionally sets `entry` and evaluates falsy. Typos like `entries` instead of `entry`.

Related errors


AI-assisted analysis of vitejs/vite@b4d66fee14 (2026-08-11). Data as JSON: /api/errors/4be66b443386e4bf. Report an issue: GitHub.

Appendix: source

Thrown at packages/vite/src/node/build.ts:606

    false,
    patchConfig,
    patchPlugins,
  )
}

export function resolveRolldownOptions(
  environment: Environment,
  chunkMetadataMap: ChunkMetadataMap,
): RolldownOptions {
  const { root, packageCache, base, build: options } = environment.config
  const libOptions = options.lib
  const { logger } = environment
  const ssr = environment.config.consumer === 'server'

  const resolve = (p: string) => path.resolve(root, p)
  const topLevelInput = environment.config.input
  if (libOptions && libOptions.entry == null) {
    throw new Error(
      `Either "build.lib.entry" or the top-level "input" option is required when "build.lib" is set.`,
    )
  }
  const input = libOptions
    ? options.rolldownOptions.input ||
      (typeof libOptions.entry === 'string'
        ? resolve(libOptions.entry)
        : Array.isArray(libOptions.entry)
          ? libOptions.entry.map(resolve)
          : Object.fromEntries(
              Object.entries(libOptions.entry!).map(([alias, file]) => [
                alias,
                resolve(file),
              ]),
            ))
    : typeof options.ssr === 'string'
      ? resolve(options.ssr)
      : options.rolldownOptions.input ||

View on GitHub (pinned to b4d66fee14)