Skip to content

fix(core): register nodenext esm resolvers at daemon startup - #36708

Draft
llwt wants to merge 2 commits into
masterfrom
fix/daemon-nodenext-esm-resolver
Draft

fix(core): register nodenext esm resolvers at daemon startup#36708
llwt wants to merge 2 commits into
masterfrom
fix/daemon-nodenext-esm-resolver

Conversation

@llwt

@llwt llwt commented Aug 19, 2026

Copy link
Copy Markdown
Member

Current Behavior

In a workspace with customConditions in tsconfig.base.json (e.g. a source condition mapping workspace packages to their TypeScript source), nx sync fails when the daemon runs a sync generator that imports a workspace library:

NX   The workspace is probably out of sync because a sync generator failed to run

[@example/nx-plugin:sync]: Cannot find module '.../packages/utils/src/lib/greet.js'
imported from .../packages/utils/src/index.ts

Since #36296 (shipped in 23.1.1) the daemon is spawned with the workspace's resolve conditions (getPluginResolveConditionNodeArgs()), so the generator's transitive workspace imports resolve to TypeScript source. That source uses NodeNext-style .js specifiers for .ts files, which need Nx's NodeNext resolver hooks, but those hooks were only ever registered in plugin worker processes (via registerPluginTSTranspiler()), never in the daemon server process, which loads and runs sync generators in-process. Note the generator entry itself resolves to built dist/*.js; the TypeScript source enters through the transitive workspace import, so registration has to be process-level rather than tied to loading a .ts entrypoint.

NX_DAEMON=false masks the bug because the CLI process runs without the injected conditions and resolves the workspace library to its built dist output instead.

Expected Behavior

The daemon registers the NodeNext .js -> .ts resolvers (ensureCjsResolverPatched() + ensureNodeNextEsmResolverRegistered()) at startup, gated on isNativeStripPreferred(), mirroring registerPluginTSTranspiler(). Sync generators whose workspace imports resolve to TypeScript source now load and run in the daemon.

Verified red/green against the minimal reproduction https://github.com/mugli/nx-esm-resolve-bug (fails on 23.1.1 and current master without this change, passes with it; the repro's NODE_OPTIONS --import resolve-hook control also passes). The new e2e (e2e/nx/src/sync.test.ts) mirrors that reproduction, was observed failing with the exact reported error before the fix, and asserts via the daemon log that the generator ran in the daemon process rather than a silently daemon-less fallback.

Related Issue(s)

No open GitHub issue. Reported in the Nx Slack (thread https://nrwl.slack.com/archives/C095YGAEJ1L/p1787141198800679?thread_ts=1769434770.555049&cid=C095YGAEJ1L) with the minimal reproduction https://github.com/mugli/nx-esm-resolve-bug.


View Polygraph session ↗

llwt added 2 commits August 19, 2026 16:24
The daemon is spawned with the workspace's resolve conditions since #36296,
so a sync generator's transitive workspace imports resolve to TypeScript
source in the daemon process. The NodeNext .js -> .ts resolver hooks were
only registered in plugin workers, so those imports failed with
ERR_MODULE_NOT_FOUND. Register them at daemon startup, mirroring
registerPluginTSTranspiler's native-strip path.
@netlify

netlify Bot commented Aug 19, 2026

Copy link
Copy Markdown

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 59c67f0
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6a85bd08ed61d200080b11fb
😎 Deploy Preview https://deploy-preview-36708--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.

@netlify

netlify Bot commented Aug 19, 2026

Copy link
Copy Markdown

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 59c67f0
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/6a85bd08cd7b8400092e0e38
😎 Deploy Preview https://deploy-preview-36708--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.

@nx-cloud

nx-cloud Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 59c67f0

Command Status Duration Result
nx affected --targets=lint,oxlint,test,build,e2... ❌ Failed 45m 18s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 31s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 13s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-19 15:15:44 UTC

@llwt
llwt requested a review from AgentEnder August 19, 2026 14:57
@llwt
llwt marked this pull request as ready for review August 19, 2026 14:57
@llwt
llwt requested a review from a team as a code owner August 19, 2026 14:57

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nx Cloud has identified a possible root cause for your failed CI:

We investigated all four failing tasks and determined they are unrelated to this PR's changes. Three failures (e2e-remix, e2e-nx-init, e2e-angular) share an identical yarn registry error — @rolldown/binding-*@1.2.5 is unavailable in the CI environment — while the fourth (e2e-react) is a build task timeout where the underlying rollup process actually completed successfully. None of the affected projects are touched by this PR, and re-running should resolve these environment-state failures.

No code changes were suggested for this issue.

Trigger a rerun:

Rerun CI

Nx Cloud View detailed reasoning on Nx Cloud ↗

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.


🎓 Learn more about Self-Healing CI on nx.dev

@llwt

llwt commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

Likely covered by #36725 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant