Replies: 3 comments 1 reply
|
The 1. Alpine uses musl libc — PGlite can have issuesPGlite bundles a WASM build of PostgreSQL. While WASM itself is libc-agnostic, PGlite's Node.js bindings and filesystem operations can behave differently on musl (Alpine) vs glibc (Debian/Ubuntu). Fix: Switch to a Debian-based image: # Instead of node:22-alpine or oven/bun:alpine
FROM oven/bun:latest
# or
FROM node:22-slimThis resolves most PGlite + Docker issues. 2. The data directory path conflictsPGlite defaults to creating its data directory relative to Fix: Use an explicit absolute path on a proper volume: import { PGlite } from '@electric-sql/pglite';
const db = new PGlite('/data/pglite');FROM node:22-slim
WORKDIR /app
RUN mkdir -p /data/pglite
COPY package*.json ./
RUN npm ci
COPY . .
VOLUME ["/data/pglite"]
CMD ["node", "index.js"]3. If you must use AlpineEnsure the data directory exists and add glibc compatibility: FROM node:22-alpine
WORKDIR /app
RUN mkdir -p /data/pglite && chmod 777 /data/pglite
RUN apk add --no-cache libc6-compat
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["node", "index.js"]4. In-memory mode (if you don't need persistence)const db = new PGlite(); // in-memory, no filesystem issuesTL;DR: Switch from Alpine to |
The minimum reproducing case.bun init
bun add @electric-sql/pgliteTouch index.ts import { PGlite } from '@electric-sql/pglite'
const client = new PGlite(process.env.DATABASE_URL)
client.exec('SELECT 1').then((res) => console.log(res))DevIt can work. $ bun run index.ts
[
{
rows: [
[Object ...]
],
fields: [
[Object ...]
],
affectedRows: 0,
}
]In dockerCreate Dockerfile FROM oven/bun:alpine AS build
WORKDIR /work
COPY package.json tsconfig.json ./
RUN bun install
COPY index.ts index.ts
RUN bun build index.ts --outdir dist
ENTRYPOINT ["bun", "run", "dist/index.js"]docker compose up Direct run ts fileMaybe pglite not support bun build? FROM oven/bun AS build
WORKDIR /work
COPY package.json bun.lock bunfig.toml tsconfig.json ./
RUN bun install
COPY index.ts index.ts
#RUN bun build index.ts --outdir dist
#ENTRYPOINT ["bun", "run", "dist/index.js"]
ENTRYPOINT ["bun", "run", "index.ts"] |
|
I found some about this [Bug] Bun bundle not work with PgLite Temporary solution |
Uh oh!
There was an error while loading. Please reload this page.
I use
bun + elysia + drizzle-orm + pglite, and i run directbun run src/index.ts, it can auto createpglite.datadir.I use it on docker
I got error
my package.json
All reactions