Skip to content

./dep.js and ./dep resolve to dep.js before dep.ts, unlike tsc and tsx #840

Closed

Description

@fengmk2

When dep.js and dep.ts sit side by side, both ./dep.js and ./dep resolve to dep.js. tsc and tsx resolve both to dep.ts. A project that compiles in place, or keeps generated .js next to its sources, therefore runs stale output.

$ cat dep.js dep.ts main.ts
export const v = 'js';
export const v = 'ts';
import { v as a } from './dep.js';
import { v as b } from './dep';
console.log('dep.js ->', a, ', dep ->', b);

$ node --import @oxc-node/core/register main.ts
dep.js -> js , dep -> js
$ tsx main.ts
dep.js -> ts , dep -> ts

Relatedly, ./x.js maps to x.tsx but not to x.jsx: with only dep.jsx present, import './dep.js' fails with ERR_MODULE_NOT_FOUND, while tsx loads dep.jsx. Reproduced with @oxc-node/[email protected] 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 resolver options (src/lib.rs#L2199-L2216) put .js first in the .js extension alias ([".js", ".ts", ".tsx"]) and before .ts in extensions, and the alias has no .jsx.

Suggested fix

For importers outside node_modules, try .ts and .tsx before .js, in the alias and in the extension list, as TypeScript's resolution does, and add .jsx to the .js alias. Inside node_modules the current order matches what packages publish.

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