{"record":{"id":"a797915eff1d684a","repo":"tailwindlabs/tailwindcss","slug":"the-path-given-to-source-must-be-a-directory","errorCode":null,"errorMessage":"The path given to `source(…)` must be a directory but got `source(${basePath})` instead.","messagePattern":"The path given to `source\\(…\\)` must be a directory but got `source\\((.+?)\\)` instead\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@tailwindcss-turbopack/src/index.ts","lineNumber":248,"sourceCode":"        // Skip negated patterns\n        if (glob.pattern[0] === '!') continue\n\n        // Avoid adding a dependency on the base directory itself\n        if (glob.pattern === '*' && base === glob.base) {\n          continue\n        }\n\n        this.addContextDependency(path.resolve(glob.base))\n      }\n\n      // Validate that source(...) paths are directories\n      let root = compiler.root\n      if (root !== 'none' && root !== null) {\n        let basePath = normalizePath(path.resolve(root.base, root.pattern))\n        try {\n          let stats = fs.statSync(basePath)\n          if (!stats.isDirectory()) {\n            throw new Error(\n              `The path given to \\`source(…)\\` must be a directory but got \\`source(${basePath})\\` instead.`,\n            )\n          }\n        } catch (err) {\n          if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {\n            throw err\n          }\n          // Directory doesn't exist yet, which is fine\n        }\n      }\n      DEBUG && I.end('Register dependency messages')\n    }\n\n    DEBUG && I.start('Build utilities')\n    let css = compiler.build([...context.candidates])\n    DEBUG && I.end('Build utilities')\n\n    // Optionally optimize the output","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/tailwindlabs/tailwindcss/blob/16e94cbf7f965c5ad697e90e940b5e178efad67c/packages/@tailwindcss-turbopack/src/index.ts#L230-L266","documentation":"The Turbopack plugin validates that every `source(…)` path resolves to an existing directory. It stats the resolved `base+pattern` path; if `statSync` succeeds but the entry is not a directory (e.g. it points at a file), it throws. Notably, `ENOENT` is swallowed — a not-yet-existing directory is tolerated so that source paths can be created during the build.","triggerScenarios":"`source(\"./src/app.tsx\")` where the path is a file rather than a directory, or `source(\"./package.json\")`. `fs.statSync(basePath)` returns stats, `isDirectory()` is false, and index.ts:248 throws. (If the path does not exist at all, no error is thrown.)","commonSituations":"Pointing `@source` at a single file path instead of a directory/glob, or a path that used to be a directory but was replaced by a file of the same name.","solutions":["Change the `source(…)` value to a directory path, or append a glob (e.g. `./src/**/*.tsx`) so the literal prefix is a directory.","If you only want one file, wrap it in a glob like `./src/app.{tsx,ts}`.","Ensure no file occupies the directory path you intend to use."],"exampleFix":"/* before */\n@source \"./src/App.tsx\";\n\n/* after */\n@source \"./src/**/*.tsx\";","handlingStrategy":"validation","validationCode":"import { statSync } from 'node:fs'\nfunction assertSourceIsDir(pattern: string, base: string) {\n  const p = path.resolve(base, pattern)\n  try {\n    if (statSync(p).isFile()) throw new Error(`source(${pattern}) is a file, not a directory`)\n  } catch (e) { if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e }\n}","typeGuard":"function isGlobPattern(s: string): boolean { return /[*{}]/.test(s) }","tryCatchPattern":null,"preventionTips":["Use directory paths or globs in source(), never bare file paths.","Confirm no file shadows an intended directory name.","Let the literal prefix of a glob be a real directory."],"tags":["turbopack","source-detection","filesystem"],"backgroundTag":null,"analyzedSha":"16e94cbf7f965c5ad697e90e940b5e178efad67c","analyzedAt":"2026-08-12T06:02:42.469Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}