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.63k stars 1.56k forks source link

Auth Payload example fails with Error: Cannot find module 'payload/dist/utilities/commitTransaction' #5011

Closed DrazenMatijacic closed 8 months ago

DrazenMatijacic commented 8 months ago

Link to reproduction

Configure as documented to use postgres and r

Describe the Bug

Configure as postgres, yarn && yarn dev

$ cross-env PAYLOAD_PUBLIC_SEED=true PAYLOAD_DROP_DATABASE=true PAYLOAD_CONFIG_PATH=src/payload.config.ts nodemon
[nodemon] 2.0.22
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: ts
[nodemon] starting `ts-node src/server.ts -- -I`
Error: Cannot find module 'payload/dist/utilities/commitTransaction'
Require stack:
- /home/node/payload/examples/auth/payload/node_modules/@payloadcms/db-postgres/dist/migrate.js
- /home/node/payload/examples/auth/payload/node_modules/@payloadcms/db-postgres/dist/index.js
- /home/node/payload/examples/auth/payload/src/payload.config.ts
- /home/node/payload/examples/auth/payload/node_modules/payload/dist/config/load.js
- /home/node/payload/examples/auth/payload/node_modules/payload/dist/payload.js
- /home/node/payload/examples/auth/payload/node_modules/payload/dist/initHTTP.js
- /home/node/payload/examples/auth/payload/node_modules/payload/dist/index.js
- /home/node/payload/examples/auth/payload/src/server.ts
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1134:15)
    at Function.Module._load (node:internal/modules/cjs/loader:975:27)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/home/node/payload/examples/auth/payload/node_modules/@payloadcms/db-postgres/dist/migrate.js:12:28)
    at Module._compile (node:internal/modules/cjs/loader:1356:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Object.require.extensions.<computed> [as .js] (/home/node/payload/examples/auth/payload/node_modules/ts-node/src/index.ts:1045:43)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1013:12)

To Reproduce

In package,json:

  "dependencies": {
    "@payloadcms/bundler-webpack": "latest",
    "@payloadcms/db-postgres": "latest",
    "@payloadcms/richtext-slate": "latest",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "payload": "latest"
  },

In payload.config.ts:

import { webpackBundler } from '@payloadcms/bundler-webpack'
import { postgresAdapter } from '@payloadcms/db-postgres'
import { slateEditor } from '@payloadcms/richtext-slate'

and

  // Configure the Postgres adapter here
  db: postgresAdapter({
    // Postgres-specific arguments go here.
    // `pool` is required.
    pool: {
      connectionString: process.env.DATABASE_URI,
    }
  }),

and in .env:

PAYLOAD_PUBLIC_SITE_URL=http://localhost:3001
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
DATABASE_URI=postgres://127.0.0.1/payload_example_auth
PAYLOAD_SECRET=PAYLOAD_AUTH_EXAMPLE_SECRET_KEY
COOKIE_DOMAIN=localhost
PAYLOAD_PUBLIC_SEED=true
PAYLOAD_DROP_DATABASE=true

and postgres:

payload_example_auth-# \l
                                                       List of databases
             Name             |  Owner   | Encoding | Collate |  Ctype  | ICU Locale | Locale Provider |   Access privileges
------------------------------+----------+----------+---------+---------+------------+-----------------+-----------------------
 demo                         | postgres | UTF8     | C       | C.UTF-8 |            | libc            |
 payload_example_auth         | node     | UTF8     | C       | C.UTF-8 |            | libc            |
 payload_example_multi_tenant | node     | UTF8     | C       | C.UTF-8 |            | libc            |
 postgres                     | postgres | UTF8     | C       | C.UTF-8 |            | libc            |
 template0                    | postgres | UTF8     | C       | C.UTF-8 |            | libc            | =c/postgres          +
                              |          |          |         |         |            |                 | postgres=CTc/postgres
 template1                    | postgres | UTF8     | C       | C.UTF-8 |            | libc            | =c/postgres          +
                              |          |          |         |         |            |                 | postgres=CTc/postgres

Please note that multitenant app works as expected.

Payload Version

main

Adapters and Plugins

db-postgres

kasbah commented 8 months ago

rm -rf yarn.lock node_modules && yarn helped when I ran into the same thing with the draft-preview example (changing it to use postgres too)

git diff ```diff diff --git a/examples/draft-preview/payload/package.json b/examples/draft-preview/payload/package.json index c71a93df8..e41c2fd1e 100644 --- a/examples/draft-preview/payload/package.json +++ b/examples/draft-preview/payload/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@payloadcms/bundler-webpack": "latest", - "@payloadcms/db-mongodb": "latest", + "@payloadcms/db-postgres": "latest", "@payloadcms/richtext-slate": "latest", "dotenv": "^8.2.0", "express": "^4.17.1", diff --git a/examples/draft-preview/payload/src/payload.config.ts b/examples/draft-preview/payload/src/payload.config.ts index bbc927fe0..206ca27b9 100644 --- a/examples/draft-preview/payload/src/payload.config.ts +++ b/examples/draft-preview/payload/src/payload.config.ts @@ -1,5 +1,5 @@ import { webpackBundler } from '@payloadcms/bundler-webpack' -import { mongooseAdapter } from '@payloadcms/db-mongodb' +import { postgresAdapter } from '@payloadcms/db-postgres' import { slateEditor } from '@payloadcms/richtext-slate' import path from 'path' import { buildConfig } from 'payload/config' @@ -18,8 +18,10 @@ export default buildConfig({ }, }, editor: slateEditor({}), - db: mongooseAdapter({ - url: process.env.DATABASE_URI, + db: postgresAdapter({ + pool: { + connectionString: process.env.DATABASE_URI, + }, }), serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL, cors: [ diff --git a/examples/draft-preview/payload/yarn.lock b/examples/draft-preview/payload/yarn.lock index 8b461c462..4099c8965 100644 --- a/examples/draft-preview/payload/yarn.lock +++ b/examples/draft-preview/payload/yarn.lock @@ -7,482 +7,12 @@ resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf" integrity sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA== ... [too many changes] ```
DanRibbens commented 8 months ago

I tested on latest packages and I am not seeing this error. As Kasbah mentioned, delete the yarn.lock and node_modules to see if that clears it up after a fresh install.

Feel free to tag me if you still have any troubles and I will reopen this issue. Thanks!

kasbah commented 8 months ago

My understanding of it was that the yarn.lock in the examples needs to be refreshed in this repo.

DrazenMatijacic commented 8 months ago

I can confirm removing yarn.lock has resolved the issue.

Kind regards, Drazen

On Wed, Feb 21, 2024 at 1:22 PM Kaspar Emanuel @.***> wrote:

My understanding of it was that the yarn.lock in the examples needs to be refreshed in this repo.

— Reply to this email directly, view it on GitHub https://github.com/payloadcms/payload/issues/5011#issuecomment-1956535390, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2O2N67A4GNCSKDCD7UXK4TYUXRJHAVCNFSM6AAAAABC4O23RKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJWGUZTKMZZGA . You are receiving this because you authored the thread.Message ID: @.***>

lekterable commented 4 months ago

For the people experiencing this error straight out of the template:

  1. Update payload - 2.0.0 -> 2.19.3 in my case
  2. Remove node_modules and package-lock.json / yarn.lock / pnpm-lock.yaml
  3. Reinstall

@DanRibbens maybe it would make sense to update dependencies in the create-payload-app templates?

they seem to be broken out of the box which is a bit frustrating

github-actions[bot] commented 1 month ago

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