{"record":{"id":"73ed876f192088b2","repo":"tailwindlabs/tailwindcss","slug":"no-loadstylesheet-function-provided-to-compile","errorCode":null,"errorMessage":"No `loadStylesheet` function provided to `compile`","messagePattern":"No `loadStylesheet` function provided to `compile`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/tailwindcss/src/index.ts","lineNumber":83,"sourceCode":"    base: string\n    module: Plugin | Config\n  }>\n  loadStylesheet?: (\n    id: string,\n    base: string,\n  ) => Promise<{\n    path: string\n    base: string\n    content: string\n  }>\n}\n\nfunction throwOnLoadModule(): never {\n  throw new Error('No `loadModule` function provided to `compile`')\n}\n\nfunction throwOnLoadStylesheet(): never {\n  throw new Error('No `loadStylesheet` function provided to `compile`')\n}\n\nfunction parseThemeOptions(params: string) {\n  let options = ThemeOptions.NONE\n  let prefix = null\n\n  for (let option of segment(params, ' ')) {\n    if (option === 'reference') {\n      options |= ThemeOptions.REFERENCE\n    } else if (option === 'inline') {\n      options |= ThemeOptions.INLINE\n    } else if (option === 'default') {\n      options |= ThemeOptions.DEFAULT\n    } else if (option === 'static') {\n      options |= ThemeOptions.STATIC\n    } else if (option.startsWith('prefix(') && option.endsWith(')')) {\n      prefix = option.slice(7, -1)\n    }","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/tailwindlabs/tailwindcss/blob/16e94cbf7f965c5ad697e90e940b5e178efad67c/packages/tailwindcss/src/index.ts#L65-L101","documentation":"Thrown by the default `loadStylesheet` stub assigned in `parseCss` when `CompileOptions.loadStylesheet` is omitted. Tailwind only invokes this callback while resolving `@import` statements via `substituteAtImports`, so the error means CSS containing `@import \"...\"` was compiled without a way to read external files. The library refuses to silently drop the imported file.","triggerScenarios":"Calling `compile(...)` or `__unstable__loadDesignSystem(...)` with CSS that contains one or more `@import` rules, while omitting `loadStylesheet` from the options object.","commonSituations":"Embedding the standalone `compile` API (or Oxide-integration layer) in a custom build pipeline, CLI, or test harness and forgetting to wire a file/URL loader. Migrating from `@tailwindcss/postcss` (which injects its own loader) to direct programmatic use.","solutions":["Provide a `loadStylesheet: async (id, base) => ({ path, base, content })` callback in `CompileOptions` that reads the file (e.g. `fs.readFile`) or fetches the URL and returns its contents.","If you do not need `@import` resolution, remove the `@import` statements from the input CSS so the loader is never called.","If integrating via the PostCSS plugin, use `@tailwindcss/postcss` instead of calling `compile` directly — it supplies a working loader."],"exampleFix":"// before\nawait compile(css) // css contains @import \"./theme.css\"\n\n// after\nimport { readFile } from 'node:fs/promises'\nimport path from 'node:path'\nawait compile(css, {\n  base: process.cwd(),\n  loadStylesheet: async (id, base) => {\n    const resolved = path.resolve(base, id)\n    return { path: resolved, base: path.dirname(resolved), content: await readFile(resolved, 'utf8') }\n  },\n})","handlingStrategy":"validation","validationCode":"// Before calling compile, detect @import and require a loader.\nimport { compile } from 'tailwindcss'\n\nfunction needsStylesheetLoader(css: string): boolean {\n  // crude but effective: matches @import (with optional layer/theme qualifiers)\n  return /@import\\s+([\"'][^\"']+[\"']|url\\()/.test(css)\n}\n\nasync function safeCompile(css: string, opts: CompileOptions = {}) {\n  if (needsStylesheetLoader(css) && !opts.loadStylesheet) {\n    throw new Error('CSS contains @import but no loadStylesheet was provided')\n  }\n  return compile(css, opts)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a `loadStylesheet` callback when the input CSS is user-supplied or may contain `@import`.","Centralize compile invocation behind a wrapper that asserts the loader is present when `@import` is detected.","In tests, reuse a `loadStylesheet` fixture (the test suite uses `async (_, base) => ({ base, path: '', content: '' })`) rather than omitting it."],"tags":["configuration","compile-options","at-import","loader"],"backgroundTag":null,"analyzedSha":"16e94cbf7f965c5ad697e90e940b5e178efad67c","analyzedAt":"2026-08-12T06:02:42.469Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}