{"record":{"id":"02202f535e55cbce","repo":"tailwindlabs/tailwindcss","slug":"the-path-given-to-source-must-be-a-directory-02202f","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-webpack/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-webpack/src/index.ts#L230-L266","documentation":"The Webpack plugin performs the same `source(…)` directory validation as Turbopack: it `statSync`s the resolved path and throws if the entry exists but is not a directory. `ENOENT` is swallowed, so a not-yet-created directory is allowed (useful when the dir is generated during the build).","triggerScenarios":"`source(\"./dist/index.html\")` where the path is a file, or any `@source` whose literal prefix resolves to an existing non-directory entry. index.ts:248 throws after `statSync` + `!isDirectory()`. (Missing paths do NOT throw.)","commonSituations":"Same-family mistake as the other bundler plugins: a file path used where a directory/glob is required, or a directory replaced by a same-named file.","solutions":["Use a directory path or a glob pattern whose non-glob prefix is a directory.","If the directory is build output, ensure it is created before the webpack build, or point `@source` at the source directory instead.","Remove any file occupying the intended directory path."],"exampleFix":"/* before */\n@source \"./pages/index.html\";\n\n/* after */\n@source \"./pages/**/*.html\";","handlingStrategy":"validation","validationCode":"import { statSync } from 'node:fs'\nfunction assertSourceDirOrMissing(pattern: string, base: string) {\n  const p = path.resolve(base, pattern)\n  try {\n    if (!statSync(p).isDirectory()) 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 isDirectory(p: string): boolean {\n  try { return statSync(p).isDirectory() } catch { return false }\n}","tryCatchPattern":null,"preventionTips":["Point source() at directories or globs, not files.","Ensure no file shadows an intended directory path.","For generated dirs, create them before the webpack build."],"tags":["webpack","source-detection","filesystem"],"backgroundTag":null,"analyzedSha":"16e94cbf7f965c5ad697e90e940b5e178efad67c","analyzedAt":"2026-08-12T06:02:42.469Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}