Skip to content

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

Merged
Coly010 merged 1 commit intomasterfrom
vite/nx-tspaths-supports-explicit-ext
Feb 27, 2025
Merged

fix(vite): ensure paths with explicit extensions are resolved #29948#30202
Coly010 merged 1 commit intomasterfrom
vite/nx-tspaths-supports-explicit-ext

Conversation

@Coly010
Copy link
Copy Markdown
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
@vercel
Copy link
Copy Markdown

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

@nx-cloud
Copy link
Copy Markdown
Contributor

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
@Coly010 Coly010 deleted the vite/nx-tspaths-supports-explicit-ext branch February 27, 2025 16:27
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 5, 2025

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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