Skip to content

Title: pgvector/kysely runtime error with kysely 0.29.x: require() async module ... is unsupported #32

@Hikariii

Description

@Hikariii

Summary

src/kysely/index.js uses CommonJS require('kysely'), which fails at runtime against kysely 0.29.x (now ESM-only / async) on Bun, and is also incompatible with Node.js require(esm) for async modules.

This is distinct from #29 / #30, which address TypeScript type resolution. This issue is about the JavaScript runtime crash.

Environment

  • pgvector: 0.2.1
  • kysely: 0.29.0+ (was dual CJS/ESM until 0.28.x; became "type": "module" and ESM-only in 0.29.0)
  • Bun: 1.3.14 (also reproducible on Node.js 22+ with NodeNext when kysely is treated as an async module)

Reproduction

mkdir pgvector-kysely-bug && cd pgvector-kysely-bug
cat > package.json <<'EOF'
{
  "type": "module",
  "dependencies": { "kysely": "0.29.2", "pgvector": "0.2.1" }
}
EOF
npm install
echo "import 'pgvector/kysely';" > test.mjs
bun test.mjs

Actual error

TypeError: require() async module "/.../node_modules/kysely/dist/index.js" is unsupported. use "await import()" instead.
    at <anonymous> (/.../node_modules/pgvector/src/kysely/index.js:1:9)

Root cause

node_modules/pgvector/src/kysely/index.js line 1:

const { sql } = require('kysely');

kysely 0.29.x is ESM-only ("type": "module") and contains top-level await, making it an async ESM module. Bun (and Node.js ≥22 in some configurations) refuses to load async ESM via CommonJS require().
This crashes the host process as soon as pgvector/kysely is loaded.

Why PR #30 does not fix this

#30 adds an index.d.mts for TypeScript type resolution under NodeNext.
It does not touch src/kysely/index.js, so the runtime require('kysely') call still happens and still fails.

Possible fixes

  1. Convert src/kysely/index.js to ESM (import { sql } from 'kysely') — breaks CommonJS consumers using require('pgvector/kysely').
  2. Dual build the /kysely subpath — ship dist/kysely/index.cjs and dist/kysely/index.mjs, wire them via the exports["./kysely"] require / import conditions.
    Same approach as the (closed) feat: Add ESM support with dual-module setup #6.
  3. Drop the /kysely helper and document the one-linertoSql and the distance helpers are short enough (sql\${col} <-> ${toSql(value)}``) that consumers can inline them; that's what we did downstream as a workaround.

Workaround for affected users

The only function we used from pgvector/kysely was toSql, which is trivially:

const vectorToSql = (vector: number[]): string => JSON.stringify(vector.map(Number));

We inlined this and dropped the pgvector dependency entirely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions