payload
payload copied to clipboard
[3.0] SyntaxError when generating types
Link to reproduction
No response
Describe the Bug
Our team just installed and setup a very basic Payload 3.0 implementation. While dev/build works fine, we have been unsuccessful in getting types generated. We are running the following:
version: 3.0.0-beta.10
command: PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types
Error:
> [email protected] payload:generate:types /Users/gregg/Code/web
> PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types
file:///Users/gregg/Code/web/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]/node_modules/payload/bin.js:3
import { register } from 'node:module'
^^^^^^^^
SyntaxError: The requested module 'node:module' does not provide an export named 'register'
payload.config.ts
import { postgresAdapter } from "@payloadcms/db-postgres"
// import { payloadCloud } from '@payloadcms/plugin-cloud'
import { lexicalEditor } from "@payloadcms/richtext-lexical" // editor-import
import path from "path"
import { buildConfig } from "payload/config"
// import sharp from 'sharp'
import { fileURLToPath } from "url"
import { PayloadCollections } from "./collections"
import { usersCollection } from "./collections/users/users-new"
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
export default buildConfig({
admin: {
user: usersCollection.slug,
},
collections: PayloadCollections,
editor: lexicalEditor({}),
// plugins: [payloadCloud()], // TODO: Re-enable when cloud supports 3.0
secret: process.env.PAYLOAD_SECRET || "",
typescript: {
outputFile: path.resolve(dirname, "payload-types.ts"),
},
db: postgresAdapter({
pool: {
connectionString: process.env.PAYLOAD_DATABASE_URI || "",
},
}),
// Sharp is now an optional dependency -
// if you want to resize images, crop, set focal point, etc.
// make sure to install it and pass it to the config.
// This is temporary - we may make an adapter pattern
// for this before reaching 3.0 stable
// sharp,
})
To Reproduce
- Install [email protected] into an existing NextJS 14 application
- Add the script:
"payload:generate:types": "PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
topackage.json
. - Run
pnpm payload:generate:types
Payload Version
3.0.0-beta.10
Adapters and Plugins
db-postgres
This is not a bug, but not documented that minimum node version is 20.6.0
as per the addition of the module.register
func:
https://nodejs.org/api/module.html#moduleregisterspecifier-parenturl-options
I also ran into this error. I can confirm that upgrading from Node 20.5.(something) to Node 22.1.0 fixed this issue.
I just ran into the same issue, but for an export from one of the other packages in my monorepo.
import { SketchPicker } from "react-color";
^^^^^^^^^^^^
SyntaxError: The requested module 'react-color' does not provide an export named 'SketchPicker'
However, this export does exist and the app builds without issue. Using Node 22.1.0 and Payload 3.0.0-beta.23.
As mentioned above, the register
function became available in 20.6.0 and 18.19.0. The engines
section for payload
has been updated accordingly
"engines": {
"node": "^18.20.2 || >=20.6.0"
},
@richardbutler Your issue seems unrelated as that is not a depdendency of payload.
This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.