Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0] SyntaxError when generating types #5868

Open
luskin opened this issue Apr 15, 2024 · 3 comments
Open

[3.0] SyntaxError when generating types #5868

luskin opened this issue Apr 15, 2024 · 3 comments
Assignees
Labels
[possible-bug] Possible bug which hasn't been reproduced yet

Comments

@luskin
Copy link

luskin commented Apr 15, 2024

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:

> web@0.1.0 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/payload@3.0.0-beta.10_@swc+core@1.4.14_@swc+types@0.1.6/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

  1. Install payload@3.0.0-beta.10 into an existing NextJS 14 application
  2. Add the script: "payload:generate:types": "PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types", to package.json.
  3. Run pnpm payload:generate:types

Payload Version

3.0.0-beta.10

Adapters and Plugins

db-postgres

@luskin luskin added the [possible-bug] Possible bug which hasn't been reproduced yet label Apr 15, 2024
@luskin
Copy link
Author

luskin commented Apr 15, 2024

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

@jamesjulich
Copy link

I also ran into this error. I can confirm that upgrading from Node 20.5.(something) to Node 22.1.0 fixed this issue.

@richardbutler
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[possible-bug] Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

4 participants