payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
24.93k stars 1.59k forks source link

Postgres Adapter: Build Error - Module not found: Can't resolve 'payload/versions' #7824

Closed pat-mw closed 2 weeks ago

pat-mw commented 2 months ago

Link to reproduction

No response

Payload Version

3.0.0-beta.90

Node Version

v20.12.2

Next.js Version

^15.0.0-rc.0

Describe the Bug

./node_modules/@payloadcms/db-postgres/dist/createGlobalVersion.js:12:1

Module not found: Can't resolve 'payload/versions'
  10 | });
  11 | const _drizzleorm = require("drizzle-orm");
> 12 | const _versions = require("payload/versions");
     | ^
  13 | const _tosnakecase = /*#__PURE__*/ _interop_require_default(require("to-snake-case"));
  14 | const _upsertRow = require("./upsertRow");
  15 | function _interop_require_default(obj) {

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:

./node_modules/@payloadcms/db-postgres/dist/index.js
./payload.config.ts
./src/app/(payload)/admin/[[...segments]]/page.tsx

The issue is a missing export in the package.json file for the latest payload dist I tried to add it below but this didn't work for me.

image

Any ideas?

Reproduction Steps

Set up boilerplate t3 stack project Upgrade to Next15 Install payload dependencies / use the cli Set up DB Connection :

// payload.config.ts

// storage-adapter-import-placeholder
import { postgresAdapter } from '@payloadcms/db-postgres' // database-adapter-import
import { lexicalEditor } from '@payloadcms/richtext-lexical'
import path from 'path'
import { buildConfig } from 'payload'
import { fileURLToPath } from 'url'
import sharp from 'sharp'

import { env } from '@/env'

import { Users } from './src/collections/Users'
import { Media } from './src/collections/Media'

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

import { PostgresAdapterResult } from '@payloadcms/db-postgres/dist/types' // Adjust the import path as necessary
import { DatabaseAdapterResult } from 'node_modules/payload/dist/database/types'

const dbConfig = postgresAdapter({
  pool: {
    connectionString: env.DATABASE_URL,
  },
});

export default buildConfig({
  admin: {
    user: Users.slug,
    importMap: {
      baseDir: path.resolve(dirname),
    },
  },
  collections: [Users, Media],
  editor: lexicalEditor(),
  secret: process.env.PAYLOAD_SECRET || '',
  typescript: {
    outputFile: path.resolve(dirname, 'payload-types.ts'),
  },
  db: dbConfig,
  sharp,
  plugins: [
    // storage-adapter-placeholder
  ],
});

NOTE: Here I am seeing another error: Type 'PostgresAdapterResult' is not assignable to type 'DatabaseAdapterResult'.ts(2322) types.d.ts(580, 5): The expected type comes from property 'db' which is declared here on type 'Config'

image

I tried to manually typecast but they dont overlap image

(alias) type PostgresAdapterResult = (args: {
    payload: Payload;
}) => any

(alias) type DatabaseAdapterResult<T = BaseDatabaseAdapter> = {
    defaultIDType: "number" | "text";
    init: (args: {
        payload: Payload;
    }) => T;
}

Adapters and Plugins

none

macamp0328 commented 2 months ago

I am experiencing the same issue. Working to add payload to an existing NextJS project, and followed the manual steps in docs.

pat-mw commented 1 month ago

any luck @macamp0328 ?

macamp0328 commented 1 month ago

any luck @macamp0328 ?

Hey @pat-mw, since I was hitting a wall, I had put the personal project down for a bit. I will spin it back up in the next few days and see what I can figure out.

r1tsuu commented 2 weeks ago

This possibly could have happened because you installed @payloadcms/db-postgres for 2.0 which uses old import payload/versions, you need to install with the beta tag pnpm add @payloadcms/db-postgres@beta.

github-actions[bot] commented 2 weeks ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.