ESLint's eslint-import-resolver-typescript does not properly resolve Node.js subpath imports when multiple file extensions are specified in the array pattern. It only checks the first extension in the array and fails to fall back to subsequent extensions.
When a subpath import is configured with multiple extensions like:
"#app/ts-first/*": ["./src/ts-first/*.ts", "./src/ts-first/*.tsx"]The resolver should try each extension in order until it finds a matching file, just like Node.js does.
The resolver only tries the first extension (.ts) and reports "Unable to resolve path to module" even when a .tsx file exists.
This reproduction case demonstrates the issue with two subpath imports having different extension orders:
#app/ts-first/*- lists.tsbefore.tsx#app/tsx-first/*- lists.tsxbefore.ts
Each directory contains both helper.ts and helper.tsx files.
-
Install dependencies:
npm install
-
Run ESLint:
npm run lint
-
Observe that
#app/ts-first/helperresolves successfully (finds.tsfirst), while#app/tsx-first/helperfails to resolve (only checks.tsx, doesn't fall back to.ts). -
For detailed output:
DEBUG=* npx eslint index.ts
- TypeScript correctly resolves both imports (verified with
npm run check) - ESLint fails to resolve imports where the first extension doesn't match an existing file
The issue is in the underlying unrs-resolver package used by eslint-import-resolver-typescript. The unrs-resolver package only tries the first pattern in a subpath import array and does not fall back to subsequent patterns if the first one doesn't match.
A minimal test case using unrs-resolver directly (without ESLint) is provided in test-unrs-resolver.cjs:
node test-unrs-resolver.cjsThis test demonstrates that:
#app/ts-first/helper-ts✓ resolves (finds.tsfile with first pattern)#app/ts-first/helper-tsx✗ fails (only tries.tspattern, doesn't try.tsx)#app/tsx-first/helper-ts✗ fails (only tries.tsxpattern, doesn't try.ts)#app/tsx-first/helper-tsx✓ resolves (finds.tsxfile with first pattern)
The resolver only succeeds when the first extension pattern matches an existing file, proving the bug is in unrs-resolver itself.