igalklebanov/kysely-surrealdb

TypeError: node_js_1.default is not a constructor

Closed this issue · 4 comments

I've just tried out using kysely, but for some reason I couldn't get it to work. The database I'm using is SurrealDB, here are the logs from Surreal:

> surreal start --log trace --user root --pass root --bind 0.0.0.0:8080 file://D:/SJ/Devs/DB/SurrealDB

2023-05-19T06:51:40.820002Z  INFO surrealdb::env: Running 1.0.0-beta.9+20230402.5eafebd for windows on x86_64    
2023-05-19T06:51:40.820058Z  INFO surrealdb::iam: Root authentication is enabled    
2023-05-19T06:51:40.820089Z  INFO surrealdb::iam: Root username is 'root'    
2023-05-19T06:51:40.820118Z  INFO surrealdb::dbs: Database strict mode is disabled    
2023-05-19T06:51:40.820208Z  INFO surrealdb::kvs: Starting kvs store at file://D:/SJ/Devs/DB/SurrealDB
2023-05-19T06:51:40.909200Z  INFO surrealdb::kvs: Started kvs store at file://D:/SJ/Devs/DB/SurrealDB
2023-05-19T06:51:40.909557Z  INFO surrealdb::net: Starting web server on 0.0.0.0:8080    
2023-05-19T06:51:40.910596Z  INFO surrealdb::net: Started web server on 0.0.0.0:8080

The Node typescript code:

import * as dotenv from 'dotenv'
dotenv.config()
import { Kysely } from "kysely";
import type { DB } from "./generated/kysely/types";
import { SurrealDatabase, SurrealDbWebSocketsDialect, type SurrealEdge } from "kysely-surrealdb";
import Surreal from "surrealdb.js";

let db: Kysely<SurrealDatabase<DB>> | null = null;

db = new Kysely<SurrealDatabase<DB>>({
	dialect: new SurrealDbWebSocketsDialect({
		Driver: Surreal,
		hostname: process.env.DATABASE_URL || "localhost:8080",
		namespace: process.env.DATABASE_NAMESPACE || "namespace",
		database: process.env.DATABASE_NAME || "name",
		username: process.env.DATABASE_USERNAME || "root",
		password: process.env.DATABASE_PASSWORD || "root",
	}),
});

console.log(await db.selectFrom("Chat").selectAll().execute());

Node just errors out:

$ pnpm ts-node index.ts

D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\surrealdb.js@0.7.2_ws@8.13.0\node_modules\surrealdb.js\src\library\SurrealSocket.ts:55
                this.ws = new WebSocket(this.url);
            ^
TypeError: node_js_1.default is not a constructor
    at SurrealSocket.open (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\surrealdb.js@0.7.2_ws@8.13.0\node_modules\surrealdb.js\src\library\SurrealSocket.ts:55:13)
    at WebSocketStrategy.connect (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\surrealdb.js@0.7.2_ws@8.13.0\node_modules\surrealdb.js\src\strategies\websocket.ts:63:15)
    at SurrealDbWebSocketsConnection.connect (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely-surrealdb@0.7.0_kysely@0.24.2_surrealdb.js@0.7.2\node_modules\kysely-surrealdb\dist\src\dialect\websockets\websockets-connection.ts:32:24)
    at SurrealDbWebSocketsDriver.connect_fn (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely-surrealdb@0.7.0_kysely@0.24.2_surrealdb.js@0.7.2\node_modules\kysely-surrealdb\dist\src\dialect\websockets\websockets-driver.ts:51:60)
    at SurrealDbWebSocketsDriver.acquireConnection (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely-surrealdb@0.7.0_kysely@0.24.2_surrealdb.js@0.7.2\node_modules\kysely-surrealdb\dist\src\dialect\websockets\websockets-driver.ts:19:40)
    at RuntimeDriver.acquireConnection (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely@0.24.2\node_modules\kysely\dist\cjs\driver\runtime-driver.js:31:47)
    at async DefaultConnectionProvider.provideConnection (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely@0.24.2\node_modules\kysely\dist\cjs\driver\default-connection-provider.js:10:28)
    at async DefaultQueryExecutor.executeQuery (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely@0.24.2\node_modules\kysely\dist\cjs\query-executor\query-executor-base.js:36:16)
    at async SelectQueryBuilder.execute (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely@0.24.2\node_modules\kysely\dist\cjs\query-builder\select-query-builder.js:1202:24)
    at async sessionStore.sessionExistsStore [as sessionExists] (D:\SJ\Devs\Github\sonicjhon1.github.io\11 WA-GawrBot\src\wa\store\sessionStore.ts:14:14)
    at async RemoteAuth.extractRemoteSession (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\whatsapp-web.js@1.19.5_bufferutil@4.0.7_utf-8-validate@5.0.10\node_modules\whatsapp-web.js\src\authStrategies\RemoteAuth.js:119:31)
    at async RemoteAuth.beforeBrowserInitialized (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\whatsapp-web.js@1.19.5_bufferutil@4.0.7_utf-8-validate@5.0.10\node_modules\whatsapp-web.js\src\authStrategies\RemoteAuth.js:60:9)
    at async Client.initialize (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\whatsapp-web.js@1.19.5_bufferutil@4.0.7_utf-8-validate@5.0.10\node_modules\whatsapp-web.js\src\Client.js:88:9)

I have also double-checked that the database is running, I could even connect to the database via Surrealist without any problems.
Screenshot 2023-05-19 153803

Edit: #10 May be related.

Note:
I'm using the prisma-kysely for generating the types from Prisma schema.

package.json
{
	"name": "@sonicjhon1/kyselytest",
	"version": "0.1.0",
	"scripts": {
		"dev": "ts-node index.ts",
		"preinstall": "npx only-allow pnpm"
	},
	"dependencies": {
		"dotenv": "^16.0.3",
		"kysely": "^0.24.2",
		"kysely-surrealdb": "^0.7.0",
		"prisma-kysely": "^1.4.0",
		"socket.io": "4.6.1",
		"surrealdb.js": "^0.7.2",
		"whatsapp-web.js": "^1.19.5"
	},
	"devDependencies": {
		"@types/ws": "8.5.4",
		"prisma": "4.14.0",
		"ts-node": "10.9.1",
		"typescript": "5.0.4"
	},
	"optionalDependencies": {
		"bufferutil": "4.0.7",
		"utf-8-validate": "5.0.10"
	}
}

Hey 👋

Can you provide a repository that reproduces this error?

Hi, it seems like some pnpm modules were not installed correctly. After doing a

pnpm install --force

This problem went away and instead the error is now the same error as #10 (same error as the minimal reproduction project linked in that issue).
Sorry if I had wasted your time in this issue...
Closing this issue as it was my fault.

You've not wasted my time, thank you!