payload icon indicating copy to clipboard operation
payload copied to clipboard

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

Open pat-mw opened this issue 1 year ago • 0 comments

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

pat-mw avatar Aug 23 '24 01:08 pat-mw