Skip to content

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

Merged
denolfe merged 1 commit into
payloadcms:3.xfrom
andershermansen:fix/ts6-css-side-effect-import
Jun 1, 2026
Merged

fix: add type declarations for css export (TypeScript 6 compat)#16348
denolfe merged 1 commit into
payloadcms:3.xfrom
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 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @andershermansen !

@denolfe denolfe merged commit 6c81355 into payloadcms:3.x Jun 1, 2026
171 of 174 checks passed
@andershermansen andershermansen deleted the fix/ts6-css-side-effect-import branch June 1, 2026 13:56
denolfe added a commit that referenced this pull request Jun 4, 2026
…#16867)

# Overview

Add TypeScript type declarations for the `./css` package export in
`@payloadcms/next`, porting
[#16348](#16348) from the
`3.x` branch.

TypeScript 6 enables
[`noUncheckedSideEffectImports`](https://www.typescriptlang.org/tsconfig/noUncheckedSideEffectImports.html)
by default. This makes `import '@payloadcms/next/css'` (present in all
of our examples/templates) fail with:

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

The published `./css` export had no `types` field, so the side-effect
import had nothing to resolve against.

## Key Changes

- **Add `src/exports/css.ts`**
- A regular TypeScript source file, consistent with the other exports,
so the existing build pipeline emits `dist/exports/css.d.ts`.

- **Wire `types` into the `./css` export**
- Added the `types` condition to both the dev and `publishConfig` export
maps in `packages/next/package.json`, pointing at the source declaration
in dev and the built `.d.ts` when published.
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🚀 This is included in version v3.85.1

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