Skip to content

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

Closed

Description

@fengmk2

Reproduction

// package.json
{ "type": "module" }
// main.ts
await import('./a.ts');
await import('./b.tsx');
// a.ts
console.log('a.ts ', typeof require, typeof module);
// b.tsx
console.log('b.tsx', typeof require, typeof module);
$ node --import @oxc-node/core/register main.ts
a.ts  undefined undefined
b.tsx function object

Expected b.tsx undefined undefined. A .jsx file in the same package behaves the same way (function object).

Files with import/export are flipped to ES modules later by load_commonjs_esm, so this hits .tsx/.jsx files without module syntax. Such a file runs with require, module, and this === module.exports in scope, and the automatic JSX runtime is emitted as require("react/jsx-runtime"), which goes through Node.js' CommonJS resolution instead of the resolve hook (tsconfig paths do not apply).

Environment: @oxc-node/core 0.1.4, Node.js 22.18.0, 24.21.0, and 26.5.0, macOS arm64.

Cause

The resolve hook takes the format from resolution.module_type() (src/lib.rs#L990-L994) and defaults to commonjs. oxc_resolver's ESM_FILE_FORMAT applies the package type only to .js and .ts and returns None for .jsx and .tsx.

Suggested fix

For jsx and tsx, fall back to the package type: resolution.package_json().and_then(|p| p.r#type()). Alternatively, oxc_resolver could cover .jsx/.tsx in module_type.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions