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): fall back to file matching when resolved file does not exist in nx-vite-ts-paths plugin #29472

Merged
merged 3 commits into from
Jan 29, 2025

Conversation

estebanfelipep
Copy link
Contributor

The fallback path resolution was only happening if the resolvedFile was a falsy value, so it was returning inexistent filepaths.

This pull request includes a small but important change to the packages/vite/plugins/nx-tsconfig-paths.plugin.ts file. The change improves the reliability of resolving file paths by checking if the resolved path exists before proceeding with fallback file matching.

Current Behavior

The resolver doesn't resolve the full file path, it ignores the file extension. For example, for a path like this:
import mergeClassNames from '@projects/global/utils/mergeClassNames'

It resolves to
absolutePath.../projects/libs/global/src/utils/mergeClassNames

When vite is building a project, it doesn't find the file and it errors.

This happens because the resolved file path is not a falsy value, thus, it doesn't run the fallback file path matching.

Expected Behavior

What is expected is that it resolves to (notice the file extension)
absolutePath.../projects/libs/global/src/utils/mergeClassNames.ts

Related Issue(s)

The fallback path resolution was only happening if the resolvedFile was a falsy value, so it was returning inexistent filepaths.
@estebanfelipep estebanfelipep requested a review from a team as a code owner December 26, 2024 17:22
Copy link

vercel bot commented Dec 26, 2024

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 Jan 29, 2025 10:31am

Copy link

nx-cloud bot commented Dec 26, 2024

View your CI Pipeline Execution ↗ for commit 7e371d9.

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 30m 25s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 14s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check --base=7d52f... ✅ Succeeded 23s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 21s View ↗
nx documentation --no-dte ✅ Succeeded 49s View ↗

☁️ Nx Cloud last updated this comment at 2025-01-29 11:02:22 UTC

@leosvelperez leosvelperez changed the title fix(nx): resolves file paths by checking if the resolved path exists before proceeding with fallback file matching. fix(vite): fall back to file matching when resolved file does not exist in nx-vite-ts-paths plugin Jan 29, 2025
Copy link
Member

@leosvelperez leosvelperez left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

@leosvelperez leosvelperez enabled auto-merge (squash) January 29, 2025 10:28
@leosvelperez leosvelperez merged commit e2e9e6c into nrwl:master Jan 29, 2025
5 checks passed
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.

2 participants