After updated to Bun 0.5.0, and using example code provided in the blog post cause an Invalid Encoding error cause from node:crypto
Code from: https://bun.sh/blog/bun-v0.5.0#sockets-using-node-tls-and-node-net
import postgres from "postgres";
const sql = postgres();
const [{ version }] = await sql`SELECT version()`;
console.log(version); // "PostgreSQL 14.2 ..."
At first I suspect that it might happens because connection error or unreachable or something, however I can use psql cli to connect to Postgres (as shown in 2nd picture)
To reproduce:
Using Docker to setup postgres:
docker run -p 5432:5432 -e POSTGRES_PASSWORD=12345678 -d postgres
Connect to postgres:
psql -h localhost -p 5432 -U postgres bun
Inside postgres cli, create database name bun:
CREATE DATABASE bun;
exit
Create file name index.ts with the following content:
import postgres from 'postgres'
const sql = postgres('postgres://postgres:12345678@localhost:5432/bun')
console.log(await sql`SELECT version();`)
Run the script and there should be a connection error.
This happens on both MacOS and WSL2 (Debian).
Tested machines:
MacOS:
Machine: Apple Silicon M1 Max
OS: MacOS Ventura 13.0.1
uname -a: Darwin Salt.local 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct 9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000 arm64
WSL:
Machine: AMD Ryzen 5 3500x
OS: Debian GNU/Linux 11 (Windows 11 WSL)
uname -a: Linux Chiffon 5.15.79.1-microsoft-standard-WSL2 #1 SMP Wed Nov 23 01:01:46 UTUC 2022 x86_64 GNU/Linux