-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
What version of Tailwind CSS are you using?
v4.2.0 (also reproduces on v4.1.18 and v4.0.0)
What build tool (or framework if applicable) are you using?
TypeScript 5.9.3
What version of Node.js are you using?
v24.13.1
What browser are you using?
N/A
What operating system are you using?
macOS
Describe your issue
When a function returns the Config type from tailwindcss and the result is exported from a file, TypeScript raises error TS2742:
error TS2742: The inferred type of 'default' cannot be named without a reference to
'./node_modules/tailwindcss/dist/types-CJYAW1ql.mjs'. This is likely not portable.
A type annotation is necessary.
This happens because tailwindcss bundles its internal types into a hashed filename (types-CJYAW1ql.d.mts). When TypeScript needs to emit a declaration file (.d.ts) for an export whose type is inferred as Config, it resolves to types defined in that hashed file. Since the hash is not a stable public export path, TypeScript refuses to reference it in generated declarations.
This is related to #15844, which was fixed for tailwindcss/plugin in #15869, but the same issue exists for the main tailwindcss entry point's Config type.
Reproduction
package.json:
{
"name": "tw-ts2742-repro",
"private": true,
"type": "module"
}tsconfig.json:
{
"compilerOptions": {
"module": "nodenext",
"moduleResolution": "nodenext",
"declaration": true,
"noEmit": true
}
}tailwind.config.ts:
import type { Config } from "tailwindcss";
function defineConfig(config: Config): Config { return config; }
export default defineConfig({});Install and run:
npm install tailwindcss@4.2.0 typescript@5.9.3
npx tscExpected: No error. The Config type is publicly exported from tailwindcss, so TypeScript should be able to reference it by its public path.
Actual:
tailwind.config.ts(3,1): error TS2742: The inferred type of 'default' cannot be named without a reference to './node_modules/tailwindcss/dist/types-CJYAW1ql.mjs'. This is likely not portable. A type annotation is necessary.
Note that explicitly annotating the variable works around the issue:
const config: Config = defineConfig({});
export default config;But this shouldn't be necessary since Config is already a public export of the package.
(Generated by Claude Code)