Repository navigation
require-in-the-middle throws in ESM (with bun and pm2?) #18859
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/bun
SDK Version
10.34.0
Framework Version
Link to Sentry event
https://lukez-dev.sentry.io/share/issue/7baae5a7125d46ca84971f6344104cf0/
Reproduction Example/SDK Setup
Here's a minimal reproduction for the Sentry error with require-in-the-middle in an ES module context:
Project Structure
sentry-repro/
├── package.json
├── .env (optional)
├── src/
│ ├── instrument.js
│ └── index.ts
└── pm2.config.js (optional)
Files
// package.json
{
"name": "sentry-repro",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "bun run --preload ./src/instrument.js src/index.ts",
"pm2": "pm2 start pm2.config.js"
},
"dependencies": {
"@sentry/bun": "^10.34.0"
},
"devDependencies": {
"@types/bun": "latest"
}
}// instrument.js
import * as Sentry from "@sentry/bun";
Sentry.init({
dsn: "https://examplekey@o1234567.ingest.sentry.io/1234567",
tracesSampleRate: 0.75,
});// index.ts
import "./instrument.js";
console.log("App started successfully");
// Keep process alive
setInterval(() => {
console.log("Still running...");
}, 5000);// pm2.config.js (ESM syntax)
export const name = "sentry-repro";
export const script = "src/index.ts";
export const interpreter = "bun";
export const interpreter_args = "--preload ./src/instrument.js";
export const env = {
NODE_ENV: "production",
};Steps to Reproduce
- Use the code above
- Run the
devorpm2script (I use pm2) - Observe
Expected Result
Should throw because it's not commonjs (require only works there)
However, sentry should work with ESM
Actual Result
Does throw because it's "type": "module"
Additional Context
I'm not quite sure if the issue is because of bun and pm2, but it is most definitely because of it being an ES module and require not working in there.
However I could trace it back the dependency tree:@sentry/bun < @sentry/node < @opentelemetry/instrumentation < require-in-the-middle
Since it is from @opentelemetry/instrumentation, maybe I should report it there as well? Or is it because of the implementation in @sentry/node ?
Priority
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.
Metadata
Metadata
Assignees
Projects
- StatusShow more project fieldsNo status
Activity
linear commentedon Jan 16, 2026
JS-1490
andreiborza commentedon Jan 16, 2026
Hi @The-LukeZ, I created a reproduction repo based on your reproduction in this issue but did not run into any issues when running it: https://github.com/andreiborza/sentry-bun-esm-repro
Could you try to see what might be different and see if you can get it into a breaking state?
karam1ashqar commentedon Jan 22, 2026
same things happens with me when i upgrade to nextjs 16.1.0
23 remaining items
The-LukeZ commentedon Jan 27, 2026
Weird, no. Only this one: https://lukez-dev.sentry.io/share/issue/46d877c6e79d469daaeb58c692792573/
logaretm commentedon Jan 27, 2026
thanks for the link, I will take a look and see if I can get it to pop up on my side
logaretm commentedon Mar 24, 2026
Circled back to this again, are you still facing this issue? I couldn't reproduce it myself but just to be clear: IITM is not supported in bun.
Having said that we have plans to improve bun and other runtimes support in a way that makes sense for each runtime's users.
In the meanwhile, LMK if you have more details since then.
The-LukeZ commentedon Mar 31, 2026
I actually found the issue - it seems to be pm2 rather than sentry. Specifying the
pm2.config.jswith ESM syntax makes pm2 freak out.Making it a
.cjsseems to resolve the issue.