Skip to content

TypeError: Cannot read properties of undefined (reading 'replace') #10

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

Closed
andreujuanc opened this issue Jan 2, 2024 · 14 comments
Closed
Labels
wontfix This will not be worked on

Comments

@andreujuanc
Copy link

Same as with this issue: #9

I'm using latest of everything and this is on nextjs 14, node 20.

I tried to understand the problem but I failed to do so.
I rolled back to pg and worked fine, therefore I think it's either postgres or this adapter.

image

@igalklebanov
Copy link
Member

Hey 👋

Can you paste your package.json's dependencies object or provide a reproduction repository?

@andreujuanc
Copy link
Author

Hi @igalklebanov , sorry but I already migrated out of nextjs.
I think MAYBE the problem is that the connection string was undefined. Not completely sure, but that might be.
Sorry.

@skelawsky
Copy link

Hey, @igalklebanov

I have the same error as op

D:\backend\node_modules\postgres\cjs\src\connection.js:389
      stack: { value: err.stack + query.origin.replace(/.*\n/, '\n'), enumerable: options.debug },
                                               ^
TypeError: Cannot read properties of undefined (reading 'replace')
    at queryError (D:\backend\node_modules\postgres\cjs\src\connection.js:389:48)
    at errored (D:\backend\node_modules\postgres\cjs\src\connection.js:384:17)
    at Socket.error (D:\backend\node_modules\postgres\cjs\src\connection.js:376:5)
    at Socket.emit (node:events:514:28)
    at Socket.emit (node:domain:489:12)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)

package.json

{
  "name": "backend",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "npx tsc",
    "start": "node dist/index.js",
    "dev": "nodemon src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "dotenv": "^16.4.2",
    "express": "^4.18.2",
    "kysely": "^0.27.2",
    "kysely-postgres-js": "^2.0.0",
    "pg": "^8.11.3"
  },
  "devDependencies": {
    "@types/express": "^4.17.21",
    "@types/node": "^20.11.17",
    "kysely-codegen": "^0.11.0",
    "nodemon": "^3.0.3",
    "ts-node": "^10.9.2",
    "typescript": "^5.3.3"
  }
}

@imwexpex
Copy link

Exactly same issue, while default pg dialect works as should.

@igalklebanov
Copy link
Member

igalklebanov commented Feb 28, 2024

"kysely-postgres-js": "^2.0.0",
"pg": "^8.11.3"

Hey 👋

This has pg in it, instead of postgres as postgres client library.
Try npm i [email protected].

@lpite
Copy link

lpite commented Feb 29, 2024

same problem next 12.3.4 or next 14

@fauh45
Copy link

fauh45 commented Mar 1, 2024

I got the same problem as well, here's the error it gives

file:///app/node_modules/postgres/src/connection.js:389
      stack: { value: err.stack + query.origin.replace(/.*\n/, '\n'), enumerable: options.debug },
                                               ^

TypeError: Cannot read properties of undefined (reading 'replace')
    at queryError (file:///app/node_modules/postgres/src/connection.js:389:48)
    at errored (file:///app/node_modules/postgres/src/connection.js:383:14)
    at TLSSocket.data (file:///app/node_modules/postgres/src/connection.js:318:9)
    at TLSSocket.emit (node:events:518:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)

Node.js v20.11.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here's the deps version I'm using

"kysely": "^0.27.2",
"kysely-postgres-js": "^2.0.0",
"postgres": "^3.4.3",

This project is purely express running on Node 20 on docker container in a kubernetes cluster.

@igalklebanov
Copy link
Member

igalklebanov commented Mar 1, 2024

This seems related to postgres, and not this package as all stack traces thus far lead to https://github.com/porsager/postgres/blob/master/src/connection.js#L389

Try using your postgres instance outside of Kysely with the same options - does it still throw an exception?

@igalklebanov
Copy link
Member

igalklebanov commented Mar 1, 2024

Closing this.

Tests are passing with Node LTS, postgres@latest, kysely@latest. https://github.com/kysely-org/kysely-postgres-js/actions/runs/8107957535

Was able to reproduce the same exception when docker container was down or by passing a wrong host option. Seems to happen because a connection cannot be established - could be due to many reasons.. the connection options are missing/wrong at runtime, your database instance refuses connections from your network OR your database instance requires something additional, SSL perhaps?

Not related to Kysely or kysely-postgres-js.

@lpite
Copy link

lpite commented Mar 1, 2024

I guess it unrelated to this adapter but host is valid because it works for some time and than nextjs hot reload crashes it and after server restart it works again

@divmgl
Copy link

divmgl commented Mar 2, 2024

I can confirm that this is related to a malformed URL. In my case I had a ?schema= in my connection string and postgres-js didn't like it. cc @porsager, it's a cryptic error message and might be worth exploring a fix.

@lpite
Copy link

lpite commented Mar 3, 2024

I can confirm that this is related to a malformed URL. In my case I had a ?schema= in my connection string and postgres-js didn't like it. cc @porsager, it's a cryptic error message and might be worth exploring a fix.

Yeah maybe but i use credentials not url and error still happens

@thanet-s
Copy link

thanet-s commented May 9, 2024

I can confirm that this is related to a malformed URL. In my case I had a ?schema= in my connection string and postgres-js didn't like it. cc @porsager, it's a cryptic error message and might be worth exploring a fix.

I remove ?schema= from url and it work

@piekczyk
Copy link

For those who have this problem still unresolved - in my case I forgot to destroy db instance after each call, so requests were creating a new clients each time. Once max client threshold was reached it failed with this ugly error:

Cannot read properties of undefined (reading 'replace') ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

9 participants