Skip to content

fix(js): resolve relative imports correctly in nested projects #31978

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

Merged
merged 2 commits into from
Jul 24, 2025

Conversation

FrozenPandaz
Copy link
Collaborator

Current Behavior

When resolving "./" imports from a nested project, the target project locator incorrectly resolves to the parent project instead of the current project.

For example, given:

  • parent-project at libs/parent-path
  • child-project at libs/parent-path/child-path (nested 1 level under parent)

When importing "./" from libs/parent-path/child-path/module.ts, it incorrectly resolves to parent-project instead of child-project.

Expected Behavior

"./" imports from within a nested project should resolve to that project, not its parent.

Related Issue(s)

Fixes #31980

When resolving "./" imports from a nested project, the target project locator
was incorrectly resolving to the parent project instead of the current project.
This was caused by trailing slashes in the resolved module path not matching
the project root mappings.

The fix removes trailing slashes from normalized resolved module paths to
ensure proper project matching.
@FrozenPandaz FrozenPandaz requested a review from a team as a code owner July 18, 2025 19:22
@FrozenPandaz FrozenPandaz requested a review from AgentEnder July 18, 2025 19:22
Copy link

vercel bot commented Jul 18, 2025

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

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview Jul 19, 2025 2:58am

Copy link
Contributor

nx-cloud bot commented Jul 18, 2025

View your CI Pipeline Execution ↗ for commit 5a47df8

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 1h 11m 33s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 1m 42s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 7s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 6s View ↗
nx documentation ✅ Succeeded 2m View ↗

☁️ Nx Cloud last updated this comment at 2025-07-19 04:05:12 UTC

@FrozenPandaz FrozenPandaz merged commit 9990b1e into master Jul 24, 2025
5 checks passed
@FrozenPandaz FrozenPandaz deleted the fix-relative-import branch July 24, 2025 18:14
jaysoo pushed a commit that referenced this pull request Jul 25, 2025
## Current Behavior

When resolving "./" imports from a nested project, the target project
locator incorrectly resolves to the parent project instead of the
current project.

For example, given:
- `parent-project` at `libs/parent-path`
- `child-project` at `libs/parent-path/child-path` (nested 1 level under
parent)

When importing "./" from `libs/parent-path/child-path/module.ts`, it
incorrectly resolves to `parent-project` instead of `child-project`.

## Expected Behavior

"./" imports from within a nested project should resolve to that
project, not its parent.

## Related Issue(s)

Fixes #31980
Copy link

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 Jul 30, 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.

Migration 21.3.0-beta.0 "Change dev.nx.gradle.project-graph to version 0.1.2 in build file" fails
3 participants