Commit 981435c
authored
fix(npm): add Node.js >= 22 version guard to npm bundle (#269)
## Problem
Users installing via pnpm (or npm/yarn without strict engine
enforcement) on Node.js < 22 get a cryptic crash at startup:
```
Error [ERR_UNKNOWN_BUILTIN_MODULE]: No such built-in module: node:sqlite
Node.js v20.18.0
```
The `bun:sqlite` polyfill in the npm bundle depends on `node:sqlite`,
which only exists in Node.js 22+. Since the polyfill is injected at the
very top of `dist/bin.cjs` via esbuild's `inject` option, the
`require('node:sqlite')` happens during module loading — before any
error handler can catch it. `package.json` already declares `"engines":
{ "node": ">=22" }`, but pnpm doesn't enforce engine constraints by
default.
## Fix
Add a version check to the esbuild bundle banner in `script/bundle.ts`.
The banner runs before the injected polyfill code, so it catches the
incompatibility before `node:sqlite` is ever required.
Users on Node < 22 now see:
```
Error: sentry requires Node.js 22 or later (found v20.18.0).
Either upgrade Node.js, or install the standalone binary instead:
curl -fsSL https://cli.sentry.dev/install | bash
```1 parent 42e4b88 commit 981435c
1 file changed
+2
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
| 99 | + | |
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| |||
0 commit comments