Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vite): ensure paths with explicit extensions are resolved #29948 #30202

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

Coly010
Copy link
Contributor

@Coly010 Coly010 commented Feb 27, 2025

Current Behavior

When TS Path Mappings are combined with an explicit extension of the build outcome of a file, the nxViteTsPaths plugin cannot resolve the file.

e.g.

import {something} from '@mylib/file.js';


// tsconfig paths

"@mylib/*": ["mylib/src/*"]

In this case, we fallback to the file system to try find the file, and we do it by adding extensions to the end of the path.

e.g.

@mylib/file.js.js
@mylib/file.js.ts
@mylib/file.js.mts
etc

Expected Behavior

Perform the usual logic first to try find the file in the file system.

If the file is still not resolved AND the path ends with an extname that we support in options.extensions, strip the extension from the path and try append the different extensions again and resolve against the filesystem.

This allows for the case where someone has a file in their file system that is file.js.js to be resolve via @mylib/file.js as well as when the explicit path is provided.

Related Issues

Fixes #29948

@Coly010 Coly010 requested a review from a team as a code owner February 27, 2025 13:00
@Coly010 Coly010 requested a review from mandarini February 27, 2025 13:00
@Coly010 Coly010 self-assigned this Feb 27, 2025
Copy link

vercel bot commented Feb 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Feb 27, 2025 1:03pm

Copy link

nx-cloud bot commented Feb 27, 2025

View your CI Pipeline Execution ↗ for commit 3fa24fa.

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 29m 48s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 16s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check --base= --he... ✅ Succeeded 6s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 5s View ↗
nx documentation ✅ Succeeded 36s View ↗

☁️ Nx Cloud last updated this comment at 2025-02-27 13:35:52 UTC

@Coly010 Coly010 merged commit a58b7ab into master Feb 27, 2025
12 checks passed
@Coly010 Coly010 deleted the vite/nx-tspaths-supports-explicit-ext branch February 27, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nxViteTsPaths plugin incorrectly handles .js extension in ESM imports
2 participants