fix: resolve TypeScript ESM .js extension imports to .ts source files#1525
Conversation
|
@chouzz is attempting to deploy a commit to the NexusCore Team on Vercel. A member of the Team first needs to authorize it. |
CI Report✅ All checks passed Pipeline Status
Test Results
✅ All 8756 tests passed 1 test(s) skipped — expand for details
Code CoverageTests
📋 View full run · Generated by CI |
|
Claude finished @magyargergo's task in 5m 0s —— View job PR #1525 Production-Readiness ReviewTasks
Review Bar for This PR
Current PR State
Branch Hygiene AssessmentClassification: clean feature/fix PR Exactly one focused commit touching three files, all scoped to the ESM import-resolver fix and its tests. No lockfile changes, no workflow churn, no unrelated formatting. The branch is up-to-date with Understanding of the ChangeBefore: After: If
Critical production path confirmed: TypeScript is in FindingsFinding 1 — Extension-pair precedence for
|
|
@chouzz Could you please look into claude's findings? 🙏 |
TypeScript ESM requires imports to use .js extensions even when source files are .ts (moduleResolution: node16/bundler). The import resolver now strips JS-family extensions (.js/.jsx/.mjs/.cjs) and retries with TS equivalents (.ts/.tsx/.mts/.cts) when the literal .js file does not exist. This fallback only applies to TypeScript/JavaScript languages. Also adds .mts/.cts to the EXTENSIONS list for completeness. Fixes abhigyanpatwari#1503
…ation test - Fix makeCtx to use production normalization (.replace backslash) instead of .toLowerCase() (Finding 3) - Add tests for .mjs/.cjs with competing .ts/.mts siblings (Finding 1) - Add tests for ./dir.js → dir/index.ts boundary (Finding 2) - Add integration test verifying full pipeline CALLS edges for ESM .js imports (Finding 4) - Document path alias .js limitation as known follow-up (Finding 5)
f7fe336 to
999b724
Compare
|
Thanks @magyargergo! I've addressed all of Claude's findings: Fixed in this update:
Follow-up issue to file:
|
| // .ts/.tsx/.mts/.cts. Strip the JS-family extension and re-resolve. | ||
| // NOTE: This fallback only applies to relative imports. Path alias imports | ||
| // (e.g. @/utils.js via tsconfig paths) do not yet strip .js extensions — | ||
| // that is a known limitation tracked for follow-up. |
There was a problem hiding this comment.
Please create a ticket for this
✨ PR AutofixFound fixable formatting / unused-import issues across 15 changed lines. Comment |
|
/autofix |
|
✅ Applied autofix and pushed a commit. (apply run) |
|
Created #1528 to track the path alias + |
Are you happy to work on it? |
Sure, you can assign to me, I will fix it. |
Co-authored-by: Cursor <cursoragent@cursor.com>
…abhigyanpatwari#1525) * fix: resolve TypeScript ESM .js extension imports to .ts source files TypeScript ESM requires imports to use .js extensions even when source files are .ts (moduleResolution: node16/bundler). The import resolver now strips JS-family extensions (.js/.jsx/.mjs/.cjs) and retries with TS equivalents (.ts/.tsx/.mts/.cts) when the literal .js file does not exist. This fallback only applies to TypeScript/JavaScript languages. Also adds .mts/.cts to the EXTENSIONS list for completeness. Fixes abhigyanpatwari#1503 * fix: address review findings — normalization, edge-case tests, integration test - Fix makeCtx to use production normalization (.replace backslash) instead of .toLowerCase() (Finding 3) - Add tests for .mjs/.cjs with competing .ts/.mts siblings (Finding 1) - Add tests for ./dir.js → dir/index.ts boundary (Finding 2) - Add integration test verifying full pipeline CALLS edges for ESM .js imports (Finding 4) - Document path alias .js limitation as known follow-up (Finding 5) * chore(autofix): apply prettier + eslint fixes via /autofix command * chore: retrigger CI after bot-only tip commit Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Gergo Magyar <gergomagyar@icloud.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Summary
Fixes #1503 — TypeScript ESM imports with
.jsextensions now correctly resolve to.tssource files.Problem
TypeScript ESM (
moduleResolution: node16/bundler) requires imports to use.jsextensions:The import resolver tried
utils.jsdirectly and appended more extensions (utils.js.ts, etc.), but never stripped.jsto try.ts. Result: 0 call edges for any ESM project.Fix
In
resolveImportPath(TS/JS relative path branch only):.js/.jsx/.mjs/.cjs), strip it and re-resolve — matching TypeScript compiler behavior..mts/.ctsto the EXTENSIONS list.The fallback is scoped to TypeScript/JavaScript only — no impact on other languages.
Testing
./utils.jsimport →context estimateTokenscorrectly shows the caller.Verification