fix(web): map Node-only specifiers to false via browser field

Browser bundlers (esbuild, webpack, vite, rollup) statically discover the
`await import("fs/promises")` and `await import("module")` calls in the
shipped ESM bundle and try to resolve them, even though both sit in
Node-only branches that never execute in a browser.

Adding a top-level `browser` field tells bundlers to substitute empty
stubs for these specifiers when targeting the browser. The runtime gates
(`globalThis.process?.versions.node` and `ENVIRONMENT_IS_NODE`) already
prevent the stubs from ever being invoked.

Fixes #5545.
This commit is contained in:
Peter Stenger 2026-04-24 23:07:59 -04:00 committed by Will Lillis
parent ac17c8d003
commit 0be5f898ad

View file

@ -43,6 +43,11 @@
},
"./debug/web-tree-sitter.wasm": "./debug/web-tree-sitter.wasm"
},
"browser": {
"fs": false,
"fs/promises": false,
"module": false
},
"types": "web-tree-sitter.d.ts",
"keywords": [
"incremental",