{"id":"4be66b443386e4bf","repo":"vitejs/vite","slug":"either-build-lib-entry-or-the-top-level-input","errorCode":null,"errorMessage":"Either \"build.lib.entry\" or the top-level \"input\" option is required when \"build.lib\" is set.","messagePattern":"Either \"build\\.lib\\.entry\" or the top-level \"input\" option is required when \"build\\.lib\" is set\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/build.ts","lineNumber":606,"sourceCode":"    false,\n    patchConfig,\n    patchPlugins,\n  )\n}\n\nexport function resolveRolldownOptions(\n  environment: Environment,\n  chunkMetadataMap: ChunkMetadataMap,\n): RolldownOptions {\n  const { root, packageCache, base, build: options } = environment.config\n  const libOptions = options.lib\n  const { logger } = environment\n  const ssr = environment.config.consumer === 'server'\n\n  const resolve = (p: string) => path.resolve(root, p)\n  const topLevelInput = environment.config.input\n  if (libOptions && libOptions.entry == null) {\n    throw new Error(\n      `Either \"build.lib.entry\" or the top-level \"input\" option is required when \"build.lib\" is set.`,\n    )\n  }\n  const input = libOptions\n    ? options.rolldownOptions.input ||\n      (typeof libOptions.entry === 'string'\n        ? resolve(libOptions.entry)\n        : Array.isArray(libOptions.entry)\n          ? libOptions.entry.map(resolve)\n          : Object.fromEntries(\n              Object.entries(libOptions.entry!).map(([alias, file]) => [\n                alias,\n                resolve(file),\n              ]),\n            ))\n    : typeof options.ssr === 'string'\n      ? resolve(options.ssr)\n      : options.rolldownOptions.input ||","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/build.ts#L588-L624","documentation":"In resolveRolldownOptions (build.ts:605), when build.lib is set but build.lib.entry is null/undefined, Vite has no entry point to bundle for the library and throws. The message notes that either build.lib.entry or the top-level input option must supply the entry.","triggerScenarios":"Configuring build: { lib: { name: 'myLib', formats: ['es'] } } without an entry field, and not providing a top-level input option either.","commonSituations":"Setting up library mode and forgetting the entry, or renaming the entry field; migrating a config where entry was previously inferred from input.","solutions":["Add build.lib.entry pointing to your entry file, e.g. entry: 'src/index.ts'.","Alternatively provide a top-level input option that the library build can fall back to.","Double-check the entry path is correct and resolvable from root."],"exampleFix":"// before\nbuild: { lib: { name: 'myLib', formats: ['es', 'umd'] } }\n// after\nbuild: { lib: { entry: 'src/index.ts', name: 'myLib', formats: ['es', 'umd'] } }","handlingStrategy":"validation","validationCode":"if (config.build?.lib && config.build.lib.entry == null && config.input == null) {\n  throw new Error('build.lib.entry (or top-level input) is required for library mode')\n}","typeGuard":"function hasLibEntry(config: UserConfig): boolean {\n  return !config.build?.lib ||\n    config.build.lib.entry != null ||\n    config.input != null\n}","tryCatchPattern":null,"preventionTips":["Always pair build.lib with an entry field.","Use a shared library-config factory so entry is never forgotten.","Lint vite.config in CI for library-mode completeness."],"tags":["build","library-mode","config","entry"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}