You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A byte order mark before a shebang makes the file fail to parse #846
A file that starts with a byte order mark followed by a shebang fails to load:
$ printf'\xef\xbb\xbf#!/usr/bin/env node\nconsole.log("bom+shebang");\n'> main.ts
$ node main.tsbom+shebang
$ node --import @oxc-node/core/register main.tsError: Failed to parse file:///…/main.ts: Invalid Character `!`
A BOM alone loads fine, and so does the same file saved as .mjs under plain Node.js. Editors on Windows often save files with a BOM, so a shebang script written there cannot run under oxc-node, while tsx runs it. Reproduced with @oxc-node/core@0.1.7 from npm on macOS arm64 with Node.js 24.12, and on 22.18 and 26.5 through an embedder that compiles in v0.1.7.
Cause
The oxc parser follows the spec: a hashbang is recognized only at the very start of the source, and a BOM is whitespace, so #! after it is an error. Hosts strip the BOM before parsing; Node.js's CommonJS loader does it with stripBOM, its ES module loader by decoding with TextDecoder, and oxc's own linter and formatter strip it before calling the parser. oxc-node passes the source to the parser with the BOM still in place. (Reported first as oxc-project/oxc#27740, which is closed in favor of this issue.)
Suggested fix
Strip a leading U+FEFF from the source before parsing, in both the load hook and the CommonJS transform.
Activity
fix(core): drop a leading byte order mark before parsing (#858)
feat(vpx): run TypeScript scripts with the vendored oxc-node (#2936)