fix(core): scope source conditions to source modules - #36725
Conversation
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit 5337f3a
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Nx Cloud has identified a flaky task in your failed CI:
🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.
🎓 Learn more about Self-Healing CI on nx.dev
…h resolver Node < 22.19 / < 24.5 hands CJS resolve hooks a Set and forwards the hook's return value to resolvers that call `.has()`, so returning an array threw `TypeError: conditions.has is not a function` for every workspace-package `require()` from a source-loaded entry on those runtimes, including when the process was already started with `--conditions`. Return the shape we were given, and state the real runtime floor in the doc comment: ESM imports only pick up hook-supplied conditions from 22.19 / 24.5.
|
Adversarial review (diff + ticket repro + the shipped hook run on real Node 22.18 / 24.4 / 26.3). Verdict before the pushed fix: needs-changes; after it: no blocking findings from my side. Fixed in 5337f3a (pushed here)
Verified: base Open for maintainers
Retitled with |
Current Behavior
When a local Nx plugin is loaded from TypeScript source, its transitive workspace-package imports do not inherit the workspace's
customConditions. In the daemon, Node can therefore select the package's default built export instead of its source export, causing sync generators to fail withERR_MODULE_NOT_FOUNDwhen that built output is absent.Starting the entire daemon with the workspace conditions fixes the failing import, but also changes resolution globally for built generators, executors, and unrelated daemon code.
Expected Behavior
Apply workspace export conditions only to known workspace-package imports reached from an explicitly source-loaded plugin, generator, or executor entry.
This change:
The reproduction using published Nx 23.1.1 fails with the daemon enabled. After copying this branch's locally built
nxpackage into the reproduction,nx syncsucceeds and runs the sync generator.Validation
pnpm nx test nx --runTestsByPath src/plugins/js/utils/register.spec.ts src/project-graph/plugins/resolve-plugin.spec.ts— 43 tests passedpnpm nx run-many -t build,lint -p nx— passedpnpm nx run e2e-plugin:typecheck— passedpnpm nx prepush— passedpnpm nx affected -t build,test,lint— 121/123 tasks passed; the remainingnx:testanddevkit:testfailures were unrelated local ANSI/hash/timing snapshot differencespnpm nx affected -t e2e-local— blocked before e2e execution because the local registry could not resolve the current@nxversionRelated Issue(s)
Fixes NXC-4816.
Alternative to #36708, following the source-scoped resolver proposal from the Linear discussion.