Repository navigation
fix(core): honor tsconfig verbatimModuleSyntax - #800
Merged
Merged
Conversation
only_remove_type_imports was hard-coded to false, so unused non-type imports were elided and their module side effects never ran — diverging from tsc and Node's own type stripping. Wire verbatim_module_syntax through so every non-type import is emitted verbatim; import type stays elided either way. Closes #798
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
The verbatimModuleSyntax fix keeps unused 'import x = require()' verbatim, which lowered to a bare require() that crashed with ReferenceError when the file runs as an ES module — where the previous elision had silently removed it. tsc rejects import=/export= in ESM output (TS1202/TS1203) and Node's type stripping rejects them at load time, so now the load hook passes Module::Esm for files that are (or flip to) ES modules, surfacing the transform error at load time instead of a runtime crash. Module::Esm emits identically to Preserve for ESM input; it only enables the diagnostics.
Brooooooklyn
added a commit
that referenced
this pull request
Oct 8, 2026
…#801) ## Summary `.jsx` and `.tsx` files in a `"type": "module"` package ran as CommonJS: oxc_resolver's `ESM_FILE_FORMAT` consults the nearest `package.json` `"type"` only for `.js` and `.ts`, so `resolution.module_type()` returned `None` for `.jsx`/`.tsx` and the resolve hook fell through to `"commonjs"`. That had two visible symptoms (issue #797): - `typeof require`/`module` were `function`/`object` instead of `undefined` - the automatic JSX runtime was emitted as `require("react/jsx-runtime")`, going through Node's CommonJS resolution — the resolve hook, and with it tsconfig `paths`, never applied The fix supplies the package `type` where `module_type()` has no answer, bounded to what Node's `ESM_FILE_FORMAT` treats as package-type territory plus the source extensions `register.mjs` claims: - **extensionless files** — Node answers them with the package type - **`.jsx`, `.tsx`, `.es`, `.es6`** — registered source extensions Node itself would reject (`ERR_UNKNOWN_FILE_EXTENSION`); we deliberately run them, so the package type is the only consistent answer - **explicit answers still win**: `.mts`/`.mjs`/`.cts`/`.cjs`/`.node`, the resolved file's tsconfig ESM `module` override (`default_module_from_tsconfig`), and `module_type()` all take precedence - **`.wasm` and unknown extensions keep the prior `commonjs` default** — reclassifying them would feed non-source files through the transformer as ES modules Running as ESM additionally means `import =`/`export =` in such a file surface the TS1202/TS1203 load-time error (merged with #800) instead of a runtime `ReferenceError`, matching `tsc` and Node's type stripping. Under `OXC_TRANSFORM_ALL`, the resolve hook now also answers formats for `node_modules` files Node.js cannot classify (`.jsx`/`.tsx`/`.es`/`.es6`, extensionless) — previously they died with `ERR_UNKNOWN_FILE_EXTENSION` before `load` could transform them. Formats Node.js *does* classify (`.ts`/`.cts`/`.mts`, `.wasm`, addons) still defer to its loaders, so Node's own errors and load paths are preserved. Closes #797 ## Test plan New `packages/integrate-vitest/__tests__/resolved-format.spec.ts` (temp-project/subprocess pattern) plus a `.jsx` row in `helper-imports.spec.ts`: - issue repro verbatim: `a.ts`, `b.tsx`, `c.jsx` with no module syntax in a `type: module` package all print `undefined` for `typeof require`/`module` - `.tsx`/`.jsx` **entry points** (no parent URL → the other resolve path) run as ESM - `type: commonjs` and no-`type` packages still run `.tsx`/`.jsx` as CJS - a tsconfig `module: commonjs` cannot demote a `.tsx` file in a `type: module` package - `.es`/`.es6` and extensionless files follow the package type in both directions - `.wasm` and `.txt` keep `commonjs` even in a `type: module` package (asserted via `createResolve`'s reported format — the fallback boundary) - the automatic JSX runtime resolves through tsconfig `paths` (the second symptom) Verified: `vp fmt` + `vp check`, `cargo test`, `pnpm test` (all integrate-* suites, 127 tests) green; the issue repro prints `a.ts: module undefined undefined` / `b.tsx: module undefined undefined`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
verbatimModuleSyntaxwas ignored:only_remove_type_importswas hard-coded tofalsein theTypeScriptOptionsliteral, so oxc-node removed unused non-typeimports and their module side effects never ran — diverging from bothtscand Node.js' own type stripping.The reporter's repro —
import { installed } from './polyfill.ts'withinstalledunused — now keeps the import, sopolyfill.tsevaluates. The flag is wired straight through:Semantics, verified against
tscand Node's type stripping:typeimport is emitted verbatim, unused bindings included — side effects runimport typeand per-specifiertypemodifiers stay elidedimport x = require()keeps its liverequire()in CommonJS output, matchingtsc'sshouldEmitAliasDeclarationextendschains (handled byoxc_resolver)Second commit (from adversarial review): keeping
import =verbatim exposed that the load hook passedModule::Preserveeven for files Node runs as ESM, so a keptimport =lowered to a barerequire()and crashed withReferenceErrorat run time (previously the unused declaration was deleted).tscrejects this (TS1202/TS1203) and Node's type stripping rejects it at load time — the hook now passesModule::Esmfor ES module files, which is emit-identical toPreservebut turns those constructs into a load-time transform error.Closes #798
Test plan
New
packages/integrate-vitest/__tests__/verbatim-module-syntax.spec.ts— 10 cases over the temp-project/subprocess pattern used byjsx-runtime.spec.ts: the issue repro (emitted code + end-to-end run order), flag-off and flag-absent elision,import typestaying elided, per-specifier and all-typespecifier lists, unused default/namespace imports,extendsinheritance, bare side-effect imports,import =in CJS output, andimport =in an ESM package failing with the TS1202 transform error instead of a runtimeReferenceError.One known divergence locked in by a test:
export { T }whereTis only a type is emitted identically with and without the flag (oxc drops the specifier either way).Known divergence (upstream, out of scope)
export { type T } from "./mod.ts"is dropped entirely, losing the module's side effects;tsc+verbatimModuleSyntaxemitsexport {} from "./mod.js", which still evaluates the dependency. Fixing requiresoxc_transformer's export-specifier cleanup (annotations.rs) to consultonly_remove_type_imports— oxc-node only sets options. Similarly,rewriteRelativeImportExtensionsdoes not rewrite the module reference insideimport =(upstreamrewrite_extensions.rsdoesn't visitTSImportEqualsDeclaration).Verified:
vp fmt+vp check,cargo test,pnpm test(all integrate-* suites, 114 tests) green; the issue repro printspolyfill.ts evaluatedthenmain.ts.