payload icon indicating copy to clipboard operation
payload copied to clipboard

Error: cannot connect to Postgres. Details: Cannot read properties of undefined (reading 'setTypeParser')

Open yayashn opened this issue 1 year ago • 22 comments

Link to reproduction

No response

Environment Info

> [email protected] payload /Users/y/Desktop/payload-catalyst
> cross-env NODE_OPTIONS=--no-deprecation payload "info"


Binaries:
  Node: 20.12.1
  npm: 10.5.0
  Yarn: N/A
  pnpm: 8.14.2
Relevant Packages:
  payload: 3.0.0-beta.96
  next: 15.0.0-canary.104
  @payloadcms/email-nodemailer: 3.0.0-beta.96
  @payloadcms/graphql: 3.0.0-beta.96
  @payloadcms/next/utilities: 3.0.0-beta.96
  @payloadcms/plugin-cloud: 3.0.0-beta.96
  @payloadcms/richtext-lexical: 3.0.0-beta.96
  @payloadcms/translations: 3.0.0-beta.96
  @payloadcms/ui/shared: 3.0.0-beta.96
  react: 19.0.0-rc-06d0b89e-20240801
  react-dom: 19.0.0-rc-06d0b89e-20240801
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:32:11 PDT 2023; root:xnu-10002.41.9~7/RELEASE_ARM64_T6030
  Available memory (MB): 36864
  Available CPU cores: 12

Describe the Bug

Get this error upon starting a blank project with vercel postgres:

[23:37:03] ERROR: Error: cannot connect to Postgres. Details: Cannot read properties of undefined (reading 'setTypeParser')

Reproduction Steps

-> pnpm create-payload-app@beta -> Choose blank project -> Enter vercel postgres database uri -> pnpm dev

Also I think the .env doesn't automatically update with the url given to the CLI tool - though the issue persists even when I manually update the env variable.

Adapters and Plugins

db-vercel-postgres

yayashn avatar Aug 29 '24 22:08 yayashn

i'm also getting this error.

i chose vercel postgres with npx create-payload-app@beta but then in vercel storage i chose the supabase integration lol. not sure if that matters but the supabase connector is new in vercel postgres.

gjohnsx avatar Aug 30 '24 16:08 gjohnsx

i'm getting the same error, looks like something wrong with db-vercel-postgres adapter. postgres with local db works fine.

xfloor avatar Aug 31 '24 20:08 xfloor

try manually adding pg to your package file. seems like there's an issue when trying to import types from pg library.

yarn add pg

calebfoster avatar Sep 02 '24 10:09 calebfoster

try manually adding pg to your package file. seems like there's an issue when trying to import types from pg library.

yarn add pg

This removes the error but now I get stuck on Pulling schema from database.... This is probably for another issue though

 ⨯ ErrorEvent {
  digest: '3527995339',
  [Symbol(kTarget)]: WebSocket {
    _events: [Object: null prototype] {
      error: [Function],
      message: [Function],
      close: [Function],
      open: [Function]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    _binaryType: 'arraybuffer',
    _closeCode: 1006,
    _closeFrameReceived: false,
    _closeFrameSent: false,
    _closeMessage: <Buffer >,
    _closeTimer: null,
    _errorEmitted: true,
    _extensions: {},
    _paused: false,
    _protocol: '',
    _readyState: 3,
    _receiver: null,
    _sender: null,
    _socket: null,
    _bufferedAmount: 0,
    _isServer: false,
    _redirects: 0,
    _autoPong: true,
    _url: 'wss://localhost/v2',
    _req: null,
    [Symbol(shapeMode)]: false,
    [Symbol(kCapture)]: false
  },
  [Symbol(kType)]: 'error',
  [Symbol(kError)]: AggregateError [ECONNREFUSED]:
      at internalConnectMultiple (node:net:1116:18)
      at afterConnectMultiple (node:net:1683:7)
      at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
    code: 'ECONNREFUSED',
    [errors]: [ [Error], [Error] ]
  },
  [Symbol(kMessage)]: ''
}

yayashn avatar Sep 02 '24 11:09 yayashn

try manually adding pg to your package file. seems like there's an issue when trying to import types from pg library.

yarn add pg

I'm not sure why this would help considering pg is not a dependency of the db-vercel-postgres package.

Looking into the actual issue, though

denolfe avatar Sep 02 '24 22:09 denolfe

Looks like there was an old drizzle issue here: https://github.com/drizzle-team/drizzle-orm/issues/505

However, it looks like that should have been merged in and fixed.

denolfe avatar Sep 02 '24 22:09 denolfe

I have the same error testing Payload 3.0 with vercel postgres 😔

t0m3t0m3 avatar Sep 04 '24 19:09 t0m3t0m3

I have reached out to Drizzle regarding this.

denolfe avatar Sep 04 '24 19:09 denolfe

Same error here. Does any one know if there is a workaround while the issue is being looked at?

christianalares avatar Sep 07 '24 12:09 christianalares

Using this "deploy to vercel" button worked for me 👌😎 https://github.com/payloadcms/vercel-deploy-payload-postgres

t0m3t0m3 avatar Sep 07 '24 19:09 t0m3t0m3

Using this "deploy to vercel" button worked for me 👌😎 https://github.com/payloadcms/vercel-deploy-payload-postgres

That template seems to use the postgresAdapter and not the vercelPostgresAdapter. I haven't dug into the code so I have no idea what it is since postgres is postgres. I don't understand why you would need another database adapter only because the postgres db is hosted on vercel but I'm sure they have a reason

christianalares avatar Sep 09 '24 10:09 christianalares

Same error here. Does any one know if there is a workaround while the issue is being looked at?

The postgres adapter still works on vercel, it's just not as lightweight because it has pg as a dependency.

denolfe avatar Sep 10 '24 00:09 denolfe

Same error here. Does any one know if there is a workaround while the issue is being looked at?

yarn add pg

should fix it for the time being. i can't remember which library when i was debugging, but maybe it was drizzle that's looking for an import from pg but is undefined until i explicitly added the dependency.

calebfoster avatar Sep 10 '24 00:09 calebfoster

@calebfoster Correct, we've reached out to them in regards to this.

denolfe avatar Sep 10 '24 00:09 denolfe

try manually adding pg to your package file. seems like there's an issue when trying to import types from pg library. yarn add pg

This removes the error but now I get stuck on Pulling schema from database.... This is probably for another issue though

 ⨯ ErrorEvent {
  digest: '3527995339',
  [Symbol(kTarget)]: WebSocket {
    _events: [Object: null prototype] {
      error: [Function],
      message: [Function],
      close: [Function],
      open: [Function]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    _binaryType: 'arraybuffer',
    _closeCode: 1006,
    _closeFrameReceived: false,
    _closeFrameSent: false,
    _closeMessage: <Buffer >,
    _closeTimer: null,
    _errorEmitted: true,
    _extensions: {},
    _paused: false,
    _protocol: '',
    _readyState: 3,
    _receiver: null,
    _sender: null,
    _socket: null,
    _bufferedAmount: 0,
    _isServer: false,
    _redirects: 0,
    _autoPong: true,
    _url: 'wss://localhost/v2',
    _req: null,
    [Symbol(shapeMode)]: false,
    [Symbol(kCapture)]: false
  },
  [Symbol(kType)]: 'error',
  [Symbol(kError)]: AggregateError [ECONNREFUSED]:
      at internalConnectMultiple (node:net:1116:18)
      at afterConnectMultiple (node:net:1683:7)
      at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
    code: 'ECONNREFUSED',
    [errors]: [ [Error], [Error] ]
  },
  [Symbol(kMessage)]: ''
}

Did you fix this in any way? Got the setTypeParser error first, after installing "pg" im stuck at your error also

BedroomDev avatar Sep 11 '24 23:09 BedroomDev

also having the same error, can't run the app at all because of it

judygab avatar Sep 16 '24 19:09 judygab

Faced the same error, subscribing to this thread

artem-tarasenko avatar Sep 17 '24 05:09 artem-tarasenko

Same error here as well.

mocon avatar Sep 17 '24 23:09 mocon

I also have the same issue

christianstamati avatar Sep 19 '24 06:09 christianstamati

What's the purpose of this adapter anyway, hasn't been working once since creation, just use @payloadcms/db-postgres and everything is fine.

marvinengelmann avatar Sep 29 '24 11:09 marvinengelmann

Any movement with this?

AlvSovereign avatar Oct 05 '24 18:10 AlvSovereign

This issue has been marked as stale due to lack of activity.

To keep this issue open, please indicate that it is still relevant in a comment below.

github-actions[bot] avatar Dec 13 '24 05:12 github-actions[bot]

This issue was automatically closed due to lack of activity.

github-actions[bot] avatar Dec 21 '24 05:12 github-actions[bot]

Hello, I've stumbled in here upon trying Payload CMS for the first time.

First I ran:

npx create-payload-app@latest

I ensured my .ENV had a valid DATABASE_URI, but the Postgres error persists.

[22:36:34] ERROR: Error: cannot connect to Postgres. Details: read ECONNRESET

So I ran:

yarn add pg

Then I got an error about sharp, and it tells me to run this command:

npm install --platform=win32 --arch=x64 sharp

Finally, payload CMS seems to boot correctly, the database is created, and I'm off to the races playing around. Thanks for this pretty cool CMS.

ghost avatar Jan 09 '25 04:01 ghost

I just spun up a fresh project, deployed to vercel and connected the neon database from vercel marketplace. Did not need to install any additional packages. Seems to be working so closing for now.

JarrodMFlesch avatar Jul 14 '25 14:07 JarrodMFlesch

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

github-actions[bot] avatar Jul 22 '25 05:07 github-actions[bot]