Skip to content
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

Drizzle + postgres not working with bun . Getting error: ResolveMessage #6555

Closed
adiSuper94 opened this issue Oct 17, 2023 · 8 comments
Closed
Labels
bug Something isn't working needs investigate Needs to be investigated to find the root cause

Comments

@adiSuper94
Copy link

adiSuper94 commented Oct 17, 2023

What version of Bun is running?

1.0.6

What platform is your computer?

Darwin 21.6.0 x86_64 i386

What steps can reproduce the bug?

package.json

{
  "name": "drizzlebuntest",
  "module": "index.ts",
  "type": "module",
  "scripts": {
    "generate": "drizzle-kit generate:pg --out migrations-folder --schema schema.ts",
    "start": "bun index.ts"
  },
  "devDependencies": {
    "bun-types": "latest",
    "drizzle-kit": "^0.19.13"
  },
  "peerDependencies": {
    "typescript": "^5.0.0"
  },
  "dependencies": {
    "drizzle-orm": "^0.28.6",
    "postgres": "^3.4.0"
  }
}

schema.ts

import { pgTable, serial, text } from "drizzle-orm/pg-core";

export const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
});

index.ts

import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import { users } from "./schema";

const client = postgres(process.env.DATABASE_URL);
const db = drizzle(client);

async function main() {
    console.log(await db.select().from(users));
}

Promise.resolve(main());

.env

 DATABASE_URL="postgres://username:password@localhost:5432/test"

setup these 4 files in project root dir.

run bun run generate, this will generate a sql file. Execute it create the DB.

run bun run start .
this results in error: ResolveMessage

rename both .ts files to .js and try running start script.
Same issue.

Now edit the start script in package.json to use node instead of bun.
"start": "node index.js "
It works as expected.

Note: I was able to get node working with ts also. but adding tsconfigs made the example more verbose.

What is the expected behavior?

It should return an empty array.

What do you see instead?

error: ResolveMessage

Additional information

Exact code/setup that works with node does not work with bun.

@adiSuper94 adiSuper94 added the bug Something isn't working label Oct 17, 2023
@adiSuper94 adiSuper94 changed the title Drizzle + postgres not working with bun Drizzle + postgres not working with bun . Getting error: ResolveMessage Oct 17, 2023
@robobun robobun changed the title Drizzle + postgres not working with bun . Getting error: ResolveMessage Drizzle + postgres not working with bun . Getting error: ResolveMessage Oct 17, 2023
@Electroid Electroid added the needs repro Needs an example to reproduce label Oct 17, 2023
@adiSuper94
Copy link
Author

Hi @Electroid. Could you tell me what the need repro label means ?
Cuz I thought I added clear steps to reproduce the issue. PLMK if you need any more info.

@matteolc
Copy link

matteolc commented Oct 17, 2023

I am also facing the same issue with postgres ^3.4.0 (no Drizzle). Trying to execute any query results in error: ResolveMessage

example.ts

import postgres from "postgres";

const sql = postgres({
  // your connection details
});

await sql`...`

bun v1.0.6 - Darwin22.0 arm64 - Darwin Kernel Version 22.5.0

@Angelelz
Copy link

+1 on this issue.
I went ahead and created a minimal reproduction repository

@masfahru
Copy link

porsager/postgres#692 (comment)

@Electroid Electroid removed the needs repro Needs an example to reproduce label Oct 19, 2023
@MariuzM
Copy link

MariuzM commented Oct 21, 2023

I use bun 1.0.7 can confirm not working

import { Elysia } from 'elysia';
import { db } from './drizzle.client';
import { test_table } from './index.schema';

(async () => {
  const t1 = await db.select().from(test_table);
  console.log(t1);
})();

Bun.serve({
  fetch(req) {
    const url = new URL(req.url);
    if (url.pathname === '/') {
      return new Response('Home page!');
    }
    return new Response('404!');
  },
});
import { PostgresJsDatabase, drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';

const client = postgres(process.env.DATABASE_URL as string);
export const db: PostgresJsDatabase = drizzle(client);
import { bigserial, pgTable, text } from 'drizzle-orm/pg-core';

export const test_table = pgTable('test', {
  id: bigserial('id', { mode: 'number' }).primaryKey().notNull(),
  name: text('name').notNull(),
});

@MariuzM
Copy link

MariuzM commented Oct 21, 2023

as suggested changing this to version "postgres": "3.3.5" solves it for now

@MonsterDeveloper
Copy link

Fixed in v3.4.1

@Electroid Electroid added the needs investigate Needs to be investigated to find the root cause label Oct 30, 2023
@Electroid
Copy link
Contributor

Fixed by porsager/postgres#692

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs investigate Needs to be investigated to find the root cause
Projects
None yet
Development

No branches or pull requests

7 participants