fix(nx): resolves file paths by checking if the resolved path exists before proceeding with fallback file matching. #29472
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.packages/vite/plugins/nx-tsconfig-paths.plugin.ts
: Added a check to verify if the resolved file path exists before using 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)