Skip to content

fix: add type declarations for css export (TypeScript 6 compat)#16348

Open
andershermansen wants to merge 1 commit intopayloadcms:mainfrom
andershermansen:fix/ts6-css-side-effect-import
Open

fix: add type declarations for css export (TypeScript 6 compat)#16348
andershermansen wants to merge 1 commit intopayloadcms:mainfrom
andershermansen:fix/ts6-css-side-effect-import

Conversation

@andershermansen
Copy link
Copy Markdown
Contributor

What?

Add TypeScript type declarations for the ./css package export in @payloadcms/next.

Why?

TypeScript 6 enables noUncheckedSideEffectImports by default. This causes import '@payloadcms/next/css' — present in all three files generated by create-payload-app — to fail with:

error TS2882: Cannot find module or type declarations for side-effect import of '@payloadcms/next/css'.

The published ./css export currently has no types field:

"./css": {
  "import": "./dist/prod/styles.css",
  "default": "./dist/prod/styles.css"
}

How?

Add src/exports/css.ts as a regular TypeScript source file (consistent with all other exports so the existing build pipeline produces dist/exports/css.d.ts. Then wire the types field into both dev and publishConfig exports.

Testing:
Tested locally by copying the new files
cp ../../payload/packages/next/dist/exports/css.* node_modules/@payloadcms/next/dist/exports
and pacthing the package.json manually:

--- original-package.json       2026-04-22 10:43:26
+++ package.json        2026-04-22 10:43:57
@@ -24,6 +24,7 @@
   "exports": {
     "./css": {
       "import": "./dist/prod/styles.css",
+      "types": "./dist/exports/css.d.ts",
       "default": "./dist/prod/styles.css"
     },
     "./withPayload": {

after that my test project builds fine with typescript 6.0.3

Fixes #16346

@andershermansen
Copy link
Copy Markdown
Contributor Author

After the build of the reproduction repo with manual patching the production run pnpm start also works fine in my testing. That is it shows the correct layout.

@denolfe denolfe added the v3 label Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript 6 compatibility: import '@payloadcms/next/css' fails with TS2882

2 participants