payloadcms / payloadcms/payload
Bug: payload generate:types fails on Windows (module resolution / ESM loader issues)
@AlessioGr is already working on this.
Since May 4, 2026.
- Dominant language
- TypeScript
- Stars
- 44.8k
- Forks
- 4.2k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 53
Description
Describe the Bug
Bug: payload generate:types fails on Windows (module resolution / ESM loader issues)
Environment
- OS: Windows 11
- Shell: PowerShell
- Node: v22.19.0
- Package managers tested:
- Bun
- npm / npx
- Framework: Next.js + Payload
- Project created using
create-payload-app
Summary
Running:
payload generate:types
fails on Windows, even in a freshly scaffolded Payload project before adding custom code.
I encountered two related issues depending on import style in payload.config.ts.
Reproduction
1. Create a fresh project
npx create-payload-app@latest
Or clone this repo
https://github.com/ahmadmh404/nextjs-16.2-payload-3.84-bug-reproduced-enviroment.git
2. Run type generation
Using Bun:
bun run generate:types
or directly:
npx payload generate:types
Issue A — Module not found with extensionless imports
Using default-style imports in payload.config.ts:
import { Users } from "./collections/Users";
produces:
Error [ERR_MODULE_NOT_FOUND]:
Cannot find module
.../src/collections/Users
imported from .../src/payload.config.ts
Example full error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module
'E:\Code\projects\multi-tenant-ecommerce\src\collections\Users'
imported from
E:\Code\projects\multi-tenant-ecommerce\src\payload.config.ts
The file exists:
src/collections/Users.ts
- File exists
- Casing is correct
- Reproduces in fresh generated project
Issue B — Adding .ts extensions changes error
Changing imports to:
import { Users } from "./collections/Users.ts";
and enabling in tsconfig.json:
"allowImportingTsExtensions": true
gets past the module resolution issue, but then type generation fails with:
Error [ERR_REQUIRE_ASYNC_MODULE]:
require() cannot be used on an ESM graph with top-level await
Full error:
Error [ERR_REQUIRE_ASYNC_MODULE]:
require() cannot be used on an ESM graph with top-level await.
Use import() instead.
Requiring .../src/payload.config.ts
Even though payload.config.ts contains no top-level await.
Minimal Config Used
Fresh generated config (no custom async logic added):
import { mongooseAdapter } from "@payloadcms/db-mongodb";
import { lexicalEditor } from "@payloadcms/richtext-lexical";
import path from "path";
import { buildConfig } from "payload";
import { fileURLToPath } from "url";
import sharp from "sharp";
import { Users } from "./collections/Users";
import { Media } from "./collections/Media";
import { Categories } from "./collections/Categories";
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
export default buildConfig({
admin: {
user: Users.slug,
importMap: {
baseDir: path.resolve(dirname),
autoGenerate: true,
},
},
collections: [Users, Media, Categories],
editor: lexicalEditor(),
secret: process.env.PAYLOAD_SECRET || "",
typescript: {
outputFile: path.resolve(dirname, "payload-types.ts"),
},
db: mongooseAdapter({
url: process.env.DATABASE_URL || "",
}),
sharp,
plugins: [],
});
No top-level await anywhere.
Expected Behavior
Running:
payload generate:types
should generate:
payload-types.ts
successfully on Windows.
Actual Behavior
Type generation fails:
-
Extensionless imports:
ERR_MODULE_NOT_FOUND
-
.tsimports:ERR_REQUIRE_ASYNC_MODULE
Both block type generation.
Additional Notes
- Reproduces on fresh generated project
- Reproduces with:
- Bun
npx payload generate:types
Appears related to one or both of:
- Windows ESM resolution for extensionless TypeScript imports
- Payload CLI config loading (
require()vs ESM import) tsxloader behavior on Windows- Possible Node 22 compatibility issue
Reproduction Repository
Minimal repro:
https://github.com/ahmadmh404/nextjs-16.2-payload-3.84-bug-reproduced-enviroment.git
Possible Areas to Investigate
- Windows ESM resolution of extensionless
.tsimports - Payload CLI loading config through
require() tsxloader interaction on Windows- Node 22 compatibility
- Bun interaction (possibly secondary)
Happy to help test patches or provide more debugging output if needed.
Link to the code that reproduces this issue
https://github.com/ahmadmh404/nextjs-16.2-payload-3.84-bug-reproduced-enviroment.git
Reproduction Steps
- Clone the reproduction repository:
git clone https://github.com/ahmadmh404/nextjs-16.2-payload-3.84-bug-reproduced-enviroment.git
cd nextjs-16.2-payload-3.84-bug-reproduced-enviroment
- Install dependencies:
Using npm:
npm install
or using Bun:
bun install
- Run type generation:
npx payload generate:types
or:
bun run generate:types
Which area(s) are affected?
area: core
Environment Info
Binaries:
Node: 22.19.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant Packages:
payload: 3.84.1
next: 16.2.4
@payloadcms/db-mongodb: 3.84.1
@payloadcms/graphql: 3.84.1
@payloadcms/next/utilities: 3.84.1
@payloadcms/richtext-lexical: 3.84.1
@payloadcms/translations: 3.84.1
@payloadcms/ui/shared: 3.84.1
react: 19.2.4
react-dom: 19.2.4
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
Available memory (MB): 12195
Available CPU cores: 8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.