Skip to content

fix(core): use scoped cache key for unresolved npm imports in TargetProjectLocator#34605

Merged
FrozenPandaz merged 1 commit intomasterfrom
fix/target-project-locator-npm-cache-key
Feb 25, 2026
Merged

fix(core): use scoped cache key for unresolved npm imports in TargetProjectLocator#34605
FrozenPandaz merged 1 commit intomasterfrom
fix/target-project-locator-npm-cache-key

Conversation

@leosvelperez
Copy link
Member

Current Behavior

TargetProjectLocator.findProjectFromImport stores null for unresolved imports using a bare importExpr key, but findNpmProjectFromImport looks up cache entries using ${packageName}__${dirPath}. The key mismatch means repeated lookups for the same import+directory re-run the full resolution waterfall (typescript + require.resolve) instead of returning the cached null.

Expected Behavior

Store null for unresolved imports using the same ${packageName}__${dirPath} key that findNpmProjectFromImport uses for lookups. Repeated lookups for already-failed imports skip the expensive resolution steps.

Also removes an unused cache write for builtin module imports as a minor cleanup.

…ProjectLocator

The npmResolutionCache lookups use `${packageName}__${dirPath}` keys,
but negative-path writes used bare `importExpr`. This meant the negative
cache was never hit, causing redundant resolution work for unresolvable
imports. Also remove dead cache write for builtin module imports.
@leosvelperez leosvelperez requested review from a team as code owners February 25, 2026 16:06
@netlify
Copy link

netlify bot commented Feb 25, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit d3419da
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/699f1e1a78581c00083d6f93
😎 Deploy Preview https://deploy-preview-34605--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Feb 25, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit d3419da
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/699f1e1ac3ee3c0008102bf4
😎 Deploy Preview https://deploy-preview-34605--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Feb 25, 2026

View your CI Pipeline Execution ↗ for commit d3419da

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 10m 35s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2m 22s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 7s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-25 19:25:03 UTC

@leosvelperez leosvelperez self-assigned this Feb 25, 2026
@leosvelperez leosvelperez changed the title fix(core): use scoped cache key for negative npm resolution in TargetProjectLocator fix(core): use scoped cache key for unresolved npm imports in TargetProjectLocator Feb 25, 2026
@FrozenPandaz FrozenPandaz merged commit 098a830 into master Feb 25, 2026
26 of 27 checks passed
@FrozenPandaz FrozenPandaz deleted the fix/target-project-locator-npm-cache-key branch February 25, 2026 20:47
FrozenPandaz pushed a commit that referenced this pull request Feb 26, 2026
…rojectLocator (#34605)

## Current Behavior

`TargetProjectLocator.findProjectFromImport` stores `null` for
unresolved imports using a bare `importExpr` key, but
`findNpmProjectFromImport` looks up cache entries using
`${packageName}__${dirPath}`. The key mismatch means repeated lookups
for the same import+directory re-run the full resolution waterfall
(typescript + require.resolve) instead of returning the cached `null`.

## Expected Behavior

Store `null` for unresolved imports using the same
`${packageName}__${dirPath}` key that `findNpmProjectFromImport` uses
for lookups. Repeated lookups for already-failed imports skip the
expensive resolution steps.

Also removes an unused cache write for builtin module imports as a minor
cleanup.

(cherry picked from commit 098a830)
FrozenPandaz pushed a commit that referenced this pull request Feb 26, 2026
…rojectLocator (#34605)

## Current Behavior

`TargetProjectLocator.findProjectFromImport` stores `null` for
unresolved imports using a bare `importExpr` key, but
`findNpmProjectFromImport` looks up cache entries using
`${packageName}__${dirPath}`. The key mismatch means repeated lookups
for the same import+directory re-run the full resolution waterfall
(typescript + require.resolve) instead of returning the cached `null`.

## Expected Behavior

Store `null` for unresolved imports using the same
`${packageName}__${dirPath}` key that `findNpmProjectFromImport` uses
for lookups. Repeated lookups for already-failed imports skip the
expensive resolution steps.

Also removes an unused cache write for builtin module imports as a minor
cleanup.

(cherry picked from commit 098a830)
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

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 3, 2026
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.

2 participants