Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jaysoo
Copy link
Member

@jaysoo jaysoo commented Dec 12, 2025

Current Behavior

When running nx serve with a NestJS project (and other node apps using runBuildTargetDependencies), the node executor attempts to resolve the nx binary using require.resolve('nx'). This fails with because nx/package.json does no longer has a main field.

Expected Behavior

The node executor should correctly resolve and use the nx binary from the workspace where it's always installed.

This is fixed by using nx/bin/nx.js instead of just nx -- as we do in other places.

Related Issue(s)

Fixes #33776

@jaysoo jaysoo requested a review from a team as a code owner December 12, 2025 16:03
@jaysoo jaysoo requested a review from Coly010 December 12, 2025 16:03
@vercel
Copy link

vercel bot commented Dec 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Dec 12, 2025 4:37pm

@netlify
Copy link

netlify bot commented Dec 12, 2025

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 25a24d0
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/693c4335a69b1900088ccdd6
😎 Deploy Preview https://deploy-preview-33842--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 Dec 12, 2025

View your CI Pipeline Execution ↗ for commit 25a24d0

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 31m 7s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 1m 39s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 6s 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 2025-12-12 17:07:01 UTC

When running `nx serve` with a NestJS project (and other node apps using
`runBuildTargetDependencies`), the node executor attempts to resolve the `nx`
binary using `require.resolve('nx')`. This fails with pnpm because:

1. `nx` is only a `devDependency` of `@nx/js`, not a regular `dependency`
2. pnpm's strict isolation prevents packages from resolving dependencies not
   declared in their package.json
3. The `nx` package doesn't have a `main` field, only `bin`, so
   `require.resolve('nx')` fails

This results in `Error: Cannot find module 'nx'` when trying to serve a
NestJS application.

The node executor should correctly resolve and use the `nx` binary from the
workspace where it's always installed.

Fixes #33776

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@jaysoo jaysoo merged commit 192099a into master Dec 12, 2025
20 checks passed
@jaysoo jaysoo deleted the issue-33776 branch December 12, 2025 17:59
FrozenPandaz pushed a commit that referenced this pull request Dec 15, 2025
## Current Behavior

When running `nx serve` with a NestJS project (and other node apps using
`runBuildTargetDependencies`), the node executor attempts to resolve the
`nx` binary using `require.resolve('nx')`. This fails with because
`nx/package.json` does no longer has a `main` field.

## Expected Behavior

The node executor should correctly resolve and use the `nx` binary from
the workspace where it's always installed.

This is fixed by using `nx/bin/nx.js` instead of just `nx` -- as we do
in other places.

## Related Issue(s)

Fixes #33776

Co-authored-by: Claude Opus 4.5 <[email protected]>
(cherry picked from commit 192099a)
FrozenPandaz pushed a commit that referenced this pull request Dec 15, 2025
## Current Behavior

When running `nx serve` with a NestJS project (and other node apps using
`runBuildTargetDependencies`), the node executor attempts to resolve the
`nx` binary using `require.resolve('nx')`. This fails with because
`nx/package.json` does no longer has a `main` field.

## Expected Behavior

The node executor should correctly resolve and use the `nx` binary from
the workspace where it's always installed.

This is fixed by using `nx/bin/nx.js` instead of just `nx` -- as we do
in other places.

## Related Issue(s)

Fixes #33776

Co-authored-by: Claude Opus 4.5 <[email protected]>
@github-actions
Copy link
Contributor

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 Dec 18, 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.

Regression in 22.2.0: @nx/nest app fails to serve immediately after generation ("Cannot find module 'nx'")

3 participants