v6.0.5 throws error when using native Bun SQL bindings
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.
looks like it's bun https://github.com/oven-sh/bun/pull/18478
yes, this is a bug in bun that will be fixed in the linked PR
yes, this is a bug in bun that will be fixed in the linked PR
Doesn't seem to fix the problem, at least for me. Tried bunx bun-pr 18478, then set interpreter option to "bun-18478".
The error message stays the same:
6|parser-bot | 150 | } catch (e) {
6|parser-bot | 151 | debug('could not resolve module: %s', moduleName)
6|parser-bot | 152 | return exports // abort if module could not be resolved (e.g. no main in package.json and no index.js file)
6|parser-bot | 153 | }
6|parser-bot | 154 |
6|parser-bot | 155 | if (res !== filename) {
6|parser-bot | ^
6|parser-bot | TypeError: require() async module "/etc/parser-bot/src/index.ts" is unsupported. use "await import()" instead.
6|parser-bot | at /root/.nvm/versions/node/v20.10.0/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:155:21
Although pm2 describe outputs correct interpreter:
│ interpreter │ bun-18478 │
│ interpreter args │ N/A │
For instance, here's the pm2 config file I use:
module.exports = {
name: "parser-bot", // Name of your application
script: "src/index.ts", // Entry point of your application
interpreter: "bun-18478", // Bun interpreter
env: {
PATH: `${process.env.HOME}/.bun/bin:${process.env.PATH}`, // Add "~/.bun/bin/bun" to PATH
}
};
i encounter the same issue
0|easy-off | 155 | if (res !== filename) {
0|easy-off | ^
0|easy-off | TypeError: require() async module "/root/dkphhh/easy-office-2/build/index.js" is unsupported. use "await import()" instead.
0|easy-off | at /root/.bun/install/global/node_modules/require-in-the-middle/index.js:155:21
0|easy-off |
0|easy-off | 150 | } catch (e) {
0|easy-off | 151 | debug('could not resolve module: %s', moduleName)
0|easy-off | 152 | return exports // abort if module could not be resolved (e.g. no main in package.json and no index.js file)
0|easy-off | 153 | }
0|easy-off | 154 |
0|easy-off | 155 | if (res !== filename) {
0|easy-off | ^
0|easy-off | TypeError: require() async module "/root/dkphhh/easy-office-2/build/index.js" is unsupported. use "await import()" instead.
0|easy-off | at /root/.bun/install/global/node_modules/require-in-the-middle/index.js:155:21
0|easy-off |
➜ ~ bun -v
1.2.13
here is my pm2 config file
module.exports = {
name: "easy-office-2", // Name of your application
script: "./build/index.js", // Entry point of your application
interpreter: "/root/.bun/bin/bun", // Bun interpreter
env: {
PATH: "/root/.bun/bin:" + process.env.PATH,
},
};
@paperclover https://github.com/oven-sh/bun/pull/18478 got merged and then quickly reverted in https://github.com/oven-sh/bun/pull/18610, so what is the plan now?
it was unreverted in https://github.com/oven-sh/bun/pull/18686 and should work. i no longer maintain the code in bun so i'm not sure about what could've changed since.
I started seeing this issue after upgrading PM2 from 5.4.2 to 6.0.8. PM2 is still running in NodeJS, using bun (1.2.20) as my app's interpreter. Supposedly this was fixed in Bun, so am I doing something wrong here?
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/ruin/SkyAnswers/src/index.ts" is unsupported. use "await import()" instead.
at <anonymous> (/home/ruin/.local/share/fnm/node-versions/v22.18.0/installation/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)
at <anonymous> (/home/ruin/.local/share/fnm/node-versions/v22.18.0/installation/lib/node_modules/pm2/lib/ProcessContainerForkBun.js:27:1)
EDIT: Also, my code isn't even using Bun SQL.
I have a same error message with interpreter bun:
TypeError: require() async module "/root/mayfest-be/src/main.ts" is unsupported. use "await import()" instead.
at /root/.bun/install/global/node_modules/require-in-the-middle/index.js:155:21
Bun v1.2.21. PM2 version: 6.0.10
Error still persists