v6.0.5 throws error when using native Bun SQL bindings
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
Apologies if this is in the wrong place, however I was not sure if I should have made this issue with Bun, require-in-the-middle, or PM2
Bun: 1.2.5
PM2: 6.0.5
OS: Ubuntu 24.04.2 LTS (GNU/Linux 6.8.0-55-generic x86_64)
Bun has a native PostgreSQL binding as documented here
With the below code, I can run it using "bun run" without any issues:
.env:
POSTGRES_URL = postgres://advance:advance@localhost:5432/advance
test-sql.ts
import { sql } from "bun";
console.log(await sql`SELECT version()`)
running:
bun run test-sql.ts
returns:
[
{
version: "PostgreSQL 16.8 (Ubuntu 16.8-0ubuntu0.24.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, 64-bit",
},
count: 1,
command: "SELECT"
]
However when I try to run the same code via PM2, I get the below error:
96 | const isPatching = patching.has(filename)
97 | if (isPatching === false) {
98 | patching.add(filename)
99 | }
100 |
101 | const exports = self._origRequire.apply(this, arguments)
^
TypeError: require() async module "/home/lemres/badvance/test-sql.ts" is unsupported. use "await import()" instead.
at <anonymous> (/home/lemres/.bun/install/global/node_modules/require-in-the-middle/index.js:101:39)
at <anonymous> (/home/lemres/.bun/install/global/node_modules/pm2/lib/ProcessContainerForkBun.js:27:1)
I have tried to start with and without interpreter, however both unfortunately returned the same error.
pm2 start test-sql.ts --name test-sql --attach
pm2 start test-sql.ts --name test-sql --attach --interpreter bun
Please let me know if I'm searching in the wrong direction or if you require any further information.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the difference between bun run test-sql.ts and the two PM2 commands using the reported Bun, PM2, and Ubuntu versions. Start at pm2/lib/ProcessContainerForkBun.js:27 and require-in-the-middle/index.js:101, then trace how test-sql.ts is loaded. Done means the native Bun SQL example runs through PM2 without the async-module error, with a regression check for this launch path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bun, postgresql, typescript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100