Skip to content

Comments

fix(resolve): support resolving TS files by JS extension specifiers in JS files#18889

Merged
patak-dev merged 2 commits intovitejs:mainfrom
sapphi-red:fix/support-resolving-ts-files-with-js-extensions
Jan 23, 2025
Merged

fix(resolve): support resolving TS files by JS extension specifiers in JS files#18889
patak-dev merged 2 commits intovitejs:mainfrom
sapphi-red:fix/support-resolving-ts-files-with-js-extensions

Conversation

@sapphi-red
Copy link
Member

Description

#8993 (comment)

In the past meeting, we decided to support .js -> .ts resolving in JS files based on moduleResolution. We thought that TS requires moduleResolution to be set to Node16 or above at that time.
But it seems TypeScript allows importing TS files by JS extension specifiers regardless of moduleResolution.
https://stackblitz.com/edit/vitejs-vite-hvbhlg?file=tsconfig.json,sub1.ts,sub2.mts,main1.js&terminal=build
Surprisingly, this behavior seems to be there since TS 2.0 🫨(microsoft/TypeScript#8895, found the link in esbuild repo).

This PR allows the .js -> .ts resolving in JS files regardless of moduleResolution.

fixes #8993
refs #5510

@sapphi-red sapphi-red added the p3-minor-bug An edge case that only affects very specific usage (priority) label Dec 5, 2024
patak-dev
patak-dev previously approved these changes Dec 5, 2024
bluwy
bluwy previously approved these changes Dec 6, 2024
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for researching that. This makes the implementation a lot simpler.

@sapphi-red sapphi-red dismissed stale reviews from bluwy and patak-dev via 445e081 December 6, 2024 05:00
Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

Thanks! There were people asking on Vitest too vitest-dev/vitest#5999

@sapphi-red
Copy link
Member Author

/ecosystem-ci run

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 10, 2024

Open in Stackblitz

npm i https://pkg.pr.new/vite@18889

commit: 445e081

@vite-ecosystem-ci

This comment was marked as outdated.

@vite-ecosystem-ci
Copy link

@patak-dev patak-dev merged commit 612332b into vitejs:main Jan 23, 2025
@sapphi-red sapphi-red deleted the fix/support-resolving-ts-files-with-js-extensions branch January 24, 2025 03:31
github-merge-queue bot pushed a commit to rolldown/rolldown that referenced this pull request Apr 23, 2025
<!-- Thank you for contributing! -->

### Description

Ported changes from the following PRs:

- vitejs/vite#18889
- vitejs/vite#19300
- vitejs/vite#18584,
vitejs/vite#19312

and some minor changes.

With this PR and #4270, the tests in Vite repo should now pass with
native resolve plugin.

<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
github-merge-queue bot pushed a commit to rolldown/rolldown that referenced this pull request Apr 23, 2025
<!-- Thank you for contributing! -->

### Description

Ported changes from the following PRs:

- vitejs/vite#18889
- vitejs/vite#19300
- vitejs/vite#18584,
vitejs/vite#19312

and some minor changes.

With this PR and #4270, the tests in Vite repo should now pass with
native resolve plugin.

<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
moonlitusun pushed a commit to moonlitusun/vite that referenced this pull request May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p3-minor-bug An edge case that only affects very specific usage (priority) trigger: preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Typescript 4.7 "Node16" extension requirements

4 participants