Repository navigation
fix(core): run .jsx/.tsx in type: module packages as ES modules - #801
Conversation
ESM_FILE_FORMAT consults the package type only for .js and .ts, so
resolution.module_type() returned None for .jsx/.tsx and the resolve
hook defaulted them to commonjs — they ran with require/module in scope
and emitted require('react/jsx-runtime'), bypassing the resolve hook and
tsconfig paths. When module_type() has no answer, fall back to the
resolved package.json type; extensionless and unknown-extension files
follow the package type too, matching Node's own algorithm.
Closes #797
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c2cae99be
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Node's ESM_FILE_FORMAT answers with the package type for any file it cannot classify — extensionless files included — not only .jsx/.tsx. Move the package.json type fallback out of the extension match so it covers extensionless paths too, and make the cjs/cts/node arm an explicit commonjs answer so .or_else cannot override it. Covers .es/.es6, which register.mjs registers as source extensions.
f4aeadf to
9203f29
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9203f290b7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Round-2 review caught that the unconditional fallback reclassified formats the resolver already classified (.wasm) and any unknown extension (.txt), feeding non-source files into the transformer as ES modules. Apply the package type only to extensionless files and the source extensions register.mjs claims (jsx/tsx/es/es6); .wasm and unknown extensions keep the previous commonjs default.
9203f29 to
2edc1ba
Compare
…M_ALL The resolve hook defers every node_modules path, so with OXC_TRANSFORM_ALL a .jsx/.tsx dependency in a type:module dep package died with ERR_UNKNOWN_FILE_EXTENSION before load could transform it. Answer the format only for files Node.js cannot classify at all (jsx/tsx/es/es6, extensionless); everything Node.js classifies (ts/cts/mts, wasm, addons) keeps deferring so its own loaders and error paths stay intact.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a66f27bfdd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The flag's consumers treat "false", "0", and "" as disabled, but the new dependency-format check used a presence test, so OXC_TRANSFORM_ALL=false still routed unclassifiable dependencies through the transformer. Extract the value-aware predicate into transform_all_enabled() and share it across all three sites so they can never disagree again.
Summary
.jsxand.tsxfiles in a"type": "module"package ran as CommonJS: oxc_resolver'sESM_FILE_FORMATconsults the nearestpackage.json"type"only for.jsand.ts, soresolution.module_type()returnedNonefor.jsx/.tsxand the resolve hook fell through to"commonjs".That had two visible symptoms (issue #797):
typeof require/modulewerefunction/objectinstead ofundefinedrequire("react/jsx-runtime"), going through Node's CommonJS resolution — the resolve hook, and with it tsconfigpaths, never appliedThe fix supplies the package
typewheremodule_type()has no answer, bounded to what Node'sESM_FILE_FORMATtreats as package-type territory plus the source extensionsregister.mjsclaims:.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.mts/.mjs/.cts/.cjs/.node, the resolved file's tsconfig ESMmoduleoverride (default_module_from_tsconfig), andmodule_type()all take precedence.wasmand unknown extensions keep the priorcommonjsdefault — reclassifying them would feed non-source files through the transformer as ES modulesRunning as ESM additionally means
import =/export =in such a file surface the TS1202/TS1203 load-time error (merged with #800) instead of a runtimeReferenceError, matchingtscand Node's type stripping.Under
OXC_TRANSFORM_ALL, the resolve hook now also answers formats fornode_modulesfiles Node.js cannot classify (.jsx/.tsx/.es/.es6, extensionless) — previously they died withERR_UNKNOWN_FILE_EXTENSIONbeforeloadcould 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.jsxrow inhelper-imports.spec.ts:a.ts,b.tsx,c.jsxwith no module syntax in atype: modulepackage all printundefinedfortypeof require/module.tsx/.jsxentry points (no parent URL → the other resolve path) run as ESMtype: commonjsand no-typepackages still run.tsx/.jsxas CJSmodule: commonjscannot demote a.tsxfile in atype: modulepackage.es/.es6and extensionless files follow the package type in both directions.wasmand.txtkeepcommonjseven in atype: modulepackage (asserted viacreateResolve's reported format — the fallback boundary)paths(the second symptom)Verified:
vp fmt+vp check,cargo test,pnpm test(all integrate-* suites, 127 tests) green; the issue repro printsa.ts: module undefined undefined/b.tsx: module undefined undefined.