{"record":{"id":"bd15fb331a38682f","repo":"tailwindlabs/tailwindcss","slug":"source-cannot-be-nested","errorCode":null,"errorMessage":"`@source` cannot be nested.","messagePattern":"`@source` cannot be nested\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/tailwindcss/src/index.ts","lineNumber":264,"sourceCode":"          }\n        }\n\n        throw new Error(\n          `\\`@utility ${node.params}\\` defines an invalid utility name. Utilities should be alphanumeric and start with a lowercase letter.`,\n        )\n      }\n\n      customUtilities.push(utility)\n    }\n\n    // Collect paths from `@source` at-rules\n    if (node.name === '@source') {\n      if (node.nodes.length > 0) {\n        throw new Error('`@source` cannot have a body.')\n      }\n\n      if (ctx.parent !== null) {\n        throw new Error('`@source` cannot be nested.')\n      }\n\n      let not = false\n      let inline = false\n      let path = node.params\n\n      if (path[0] === 'n' && path.startsWith('not ')) {\n        not = true\n        path = path.slice(4)\n      }\n\n      if (path[0] === 'i' && path.startsWith('inline(')) {\n        inline = true\n        path = path.slice(7, -1).trim()\n      }\n\n      if (\n        (path[0] === '\"' && path[path.length - 1] !== '\"') ||","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/tailwindlabs/tailwindcss/blob/16e94cbf7f965c5ad697e90e940b5e178efad67c/packages/tailwindcss/src/index.ts#L246-L282","documentation":"Thrown when an `@source` at-rule is encountered with a non-null parent (`ctx.parent !== null`). Like `@utility`, `@source` is a top-level directive; nesting it under `@media`, a selector rule, or any other block is rejected immediately after the no-body check.","triggerScenarios":"Placing `@source` inside `@media`, inside a selector, or inside another at-rule, e.g. `.theme { @source \"./theme/**/*.html\"; }`.","commonSituations":"Trying to scope source discovery to a sub-tree; preprocessors that wrap content; refactors that indent directives.","solutions":["Move the `@source` statement to the top level of the stylesheet.","Use globs to narrow scope rather than structural nesting: `@source \"./theme/**/*.html\"`.","Use `@source not(\"...\")` to exclude paths instead of wrapping in conditional rules."],"exampleFix":"/* before */\n.theme-dark {\n  @source \"./dark/**/*.html\";\n}\n\n/* after */\n@source \"./dark/**/*.html\";","handlingStrategy":"validation","validationCode":"// Reject nested @source the same way the library does.\nimport postcss from 'postcss'\n\nfunction validateSourceIsTopLevel(css: string): string[] {\n  const errors: string[] = []\n  postcss.parse(css).walkAtRules('@source', (rule) => {\n    if (rule.parent && rule.parent.type !== 'root') {\n      errors.push(`@source ${rule.params} must be at the top level`)\n    }\n  })\n  return errors\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep `@source` directives at the top of the stylesheet, near other configuration at-rules.","Use `@source not(\"...\")` to exclude paths rather than wrapping in conditional blocks.","Lint for any non-root parent of statement at-rules."],"tags":["at-source","nesting","structure"],"backgroundTag":null,"analyzedSha":"16e94cbf7f965c5ad697e90e940b5e178efad67c","analyzedAt":"2026-08-12T06:02:42.469Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}