Skip to content

fix(core): run .jsx/.tsx in type: module packages as ES modules - #801

Merged
Brooooooklyn merged 5 commits into
mainfrom
fix/jsx-tsx-module-format
Oct 8, 2026
Merged

Brooooooklyn merged 5 commits into
mainfrom
fix/jsx-tsx-module-format

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

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.

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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T09:24:01.532624Z 9a73144 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/lib.rs Resolved
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.
@Brooooooklyn
Brooooooklyn force-pushed the fix/jsx-tsx-module-format branch 2 times, most recently from f4aeadf to 9203f29 Compare October 8, 2026 08:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/lib.rs Resolved
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.
@Brooooooklyn
Brooooooklyn force-pushed the fix/jsx-tsx-module-format branch from 9203f29 to 2edc1ba Compare October 8, 2026 08:26
…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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/lib.rs Resolved
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.
@Brooooooklyn
Brooooooklyn merged commit 28ccab0 into main Oct 8, 2026
65 of 66 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/jsx-tsx-module-format branch October 8, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.tsx and .jsx files in a "type": "module" package run as CommonJS

1 participant