{"id":"024c234125b5156b","repo":"vitejs/vite","slug":"when-build-csscodesplit-false-is-set-rolldown","errorCode":null,"errorMessage":"When \"build.cssCodeSplit: false\" is set, \"rolldownOptions.input\" should not include CSS files.","messagePattern":"When \"build\\.cssCodeSplit: false\" is set, \"rolldownOptions\\.input\" should not include CSS files\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/build.ts","lineNumber":641,"sourceCode":"      ? resolve(options.ssr)\n      : options.rolldownOptions.input ||\n        (topLevelInput ?? resolve('index.html'))\n\n  if (ssr && typeof input === 'string' && input.endsWith('.html')) {\n    throw new Error(\n      `rolldownOptions.input should not be an html file when building for SSR. ` +\n        `Please specify a dedicated SSR entry.`,\n    )\n  }\n  if (options.cssCodeSplit === false) {\n    const inputs =\n      typeof input === 'string'\n        ? [input]\n        : Array.isArray(input)\n          ? input\n          : Object.values(input)\n    if (inputs.some((input) => input.endsWith('.css'))) {\n      throw new Error(\n        `When \"build.cssCodeSplit: false\" is set, \"rolldownOptions.input\" should not include CSS files.`,\n      )\n    }\n  }\n\n  const outDir = resolve(options.outDir)\n\n  // inject environment and ssr arg to plugin load/transform hooks\n  const plugins = environment.plugins.map((p) =>\n    injectEnvironmentToHooks(environment, chunkMetadataMap, p),\n  )\n\n  const rolldownOptions: RolldownOptions = {\n    preserveEntrySignatures: ssr\n      ? 'allow-extension'\n      : libOptions\n        ? 'strict'\n        : false,","sourceCodeStart":623,"sourceCodeEnd":659,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/build.ts#L623-L659","documentation":"In resolveRolldownOptions (build.ts:633-644), when build.cssCodeSplit is false and any resolved input ends in .css, Vite throws. With code splitting disabled, CSS cannot be treated as a separate entry; CSS must be imported from JS rather than listed directly as an input.","triggerScenarios":"Setting build: { cssCodeSplit: false } while rolldownOptions.input (or the default input) includes one or more .css files.","commonSituations":"Trying to ship a single combined CSS file by disabling code splitting, but also listing the stylesheet as a build entry; copying a multi-entry config that included a CSS entry.","solutions":["Remove .css files from rolldownOptions.input and import the CSS from a JS/TS entry instead.","If you genuinely need CSS as an entry, leave cssCodeSplit at its default (true).","Move shared styles into a JS entry that does import './styles.css'."],"exampleFix":"// before\nbuild: { cssCodeSplit: false, rollupOptions: { input: { main: 'src/main.ts', styles: 'src/styles.css' } } }\n// after\nbuild: { cssCodeSplit: false, rollupOptions: { input: { main: 'src/main.ts' } } } // src/main.ts imports './styles.css'","handlingStrategy":"validation","validationCode":"if (config.build?.cssCodeSplit === false) {\n  const inputs = config.build?.rolldownOptions?.input\n  const list = typeof inputs === 'string' ? [inputs] : Array.isArray(inputs) ? inputs : inputs ? Object.values(inputs) : []\n  if (list.some((f) => f.endsWith('.css'))) {\n    throw new Error('CSS inputs are not allowed when cssCodeSplit is false')\n  }\n}","typeGuard":"function hasNoCssInput(inputs: unknown): boolean {\n  const list = typeof inputs === 'string' ? [inputs] : Array.isArray(inputs) ? inputs : inputs ? Object.values(inputs as Record<string, string>) : []\n  return !list.some((f: string) => f.endsWith('.css'))\n}","tryCatchPattern":null,"preventionTips":["Import CSS from JS entries rather than listing stylesheets as inputs.","If you need CSS entries, keep cssCodeSplit at its default (true).","Review rolldownOptions.input whenever toggling cssCodeSplit."],"tags":["build","css","config","entry"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}