Skip to content
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

Cannot Serve Project from Project Root for a NestJS project #30087

Open
1 of 4 tasks
MisterPandaPooh opened this issue Feb 18, 2025 · 1 comment · May be fixed by #30091
Open
1 of 4 tasks

Cannot Serve Project from Project Root for a NestJS project #30087

MisterPandaPooh opened this issue Feb 18, 2025 · 1 comment · May be fixed by #30091

Comments

@MisterPandaPooh
Copy link

MisterPandaPooh commented Feb 18, 2025

Current Behavior

When running nx run user-service:serve from the project root, I encounter an error after updating from [email protected] to nx@latest. However, executing the same command from the workspace root works correctly. This issue wasn't present with [email protected].

The issue seems to appears only in nest project, I tested react project Its not happening.

Expected Behavior

To enable running nx nest targets not only from the workspace root but also from the project root.

GitHub Repo

https://github.com/MisterPandaPooh/nx-cwd-issue

Steps to Reproduce

  1. Create a new workspace with [email protected], using [email protected], including one nest project in service/user-service and one react project with Module Federation in platform/ui-host and platform/ui-remote.
# Create a new workspace
npx [email protected]  #(No Stack, Integrated Monorepo)
yarn

# Add the following plugins
nx add @nx/react
nx add @nx/express
nx add @nx/nest
nx add @nx/node
nx add @nx/plugin
nx add @nx/cypress

# Generate the host project (not really related to the issue)
nx generate @nx/react:host --name=ui-host --directory=platform/ui-host --e2eTestRunner=none --unitTestRunner=jest --minimal=true --projectNameAndRootFormat=as-provided --setParserOptionsProject=true --style=none --no-interactive
nx generate @nx/cypress:configuration --project=ui-host --setParserOptionsProject=true --no-interactive


# Generate the remote project  (not really related to the issue)
nx generate @nx/react:remote --name=ui-remote --directory=platform/ui-remote --host=ui-host --e2eTestRunner=none --projectNameAndRootFormat=as-provided --setParserOptionsProject=true --style=none --unitTestRunner=jest --no-interactive
nx generate @nx/cypress:configuration --project=ui-remote --setParserOptionsProject=true --no-interactive

# Generate the nest project
nx g @nx/nest:application user-service --directory=services/user-service --projectNameAndRootFormat=as-provided
  1. Run nx run user-service:serve in the root of the workspace or in the service/user-service directory. The nest project will start successfully.

  2. Migrate to nx@latest.

npx nx migrate latest
npx nx migrate --run-migrations
  1. Run nx run user-service:serve in the root will work fine. But running the same command in the service/user-service directory will throw the following error:
Debugger attached.
Waiting for the debugger to disconnect...
/Users/super.user/Documents/Workspaces/nx-issue-cwd/node_modules/@nx/js/src/executors/node/node.impl.js:331
    throw new Error(`Could not find ${fileToRun}. Make sure your build succeeded.`);
          ^

Error: Could not find dist/services/user-service/main.js. Make sure your build succeeded.
    at fileToRunCorrectPath (/Users/super.user/Documents/Workspaces/nx-issue-cwd/node_modules/@nx/js/src/executors/node/node.impl.js:331:11)
    at /Users/super.user/Documents/Workspaces/nx-issue-cwd/node_modules/@nx/js/src/executors/node/node.impl.js:114:49
    at new Promise (<anonymous>)
    at Object.start (/Users/super.user/Documents/Workspaces/nx-issue-cwd/node_modules/@nx/js/src/executors/node/node.impl.js:108:36)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async processQueue (/Users/super.user/Documents/Workspaces/nx-issue-cwd/node_modules/@nx/js/src/executors/node/node.impl.js:79:13)

Node.js v20.12.2
Waiting for the debugger to disconnect...

Note: I only added react project to reflect my nx workspace setup. There is no direct link with react project.

Nx Report

Node           : 20.12.2
OS             : darwin-arm64
Native Target  : aarch64-macos
yarn           : 1.22.22

nx (global)            : 20.4.2
nx                     : 20.4.4
@nx/js                 : 20.4.4
@nx/jest               : 20.4.4
@nx/eslint             : 20.4.4
@nx/workspace          : 20.4.4
@nx/cypress            : 20.4.4
@nx/devkit             : 20.4.4
@nx/eslint-plugin      : 20.4.4
@nx/express            : 20.4.4
@nx/module-federation  : 20.4.4
@nx/nest               : 20.4.4
@nx/node               : 20.4.4
@nx/plugin             : 20.4.4
@nx/react              : 20.4.4
@nx/web                : 20.4.4
@nx/webpack            : 20.4.4
typescript             : 5.7.3
---------------------------------------
Registered Plugins:
@nx/cypress/plugin
@nx/webpack/plugin
@nx/eslint/plugin

Failure Logs

Debugger attached.
Waiting for the debugger to disconnect...
/Users/super.user/Documents/Workspaces/nx-issue-cwd/node_modules/@nx/js/src/executors/node/node.impl.js:331
    throw new Error(`Could not find ${fileToRun}. Make sure your build succeeded.`);
          ^

Error: Could not find dist/services/user-service/main.js. Make sure your build succeeded.
    at fileToRunCorrectPath (/Users/super.user/Documents/Workspaces/nx-issue-cwd/node_modules/@nx/js/src/executors/node/node.impl.js:331:11)
    at /Users/super.user/Documents/Workspaces/nx-issue-cwd/node_modules/@nx/js/src/executors/node/node.impl.js:114:49
    at new Promise (<anonymous>)
    at Object.start (/Users/super.user/Documents/Workspaces/nx-issue-cwd/node_modules/@nx/js/src/executors/node/node.impl.js:108:36)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async processQueue (/Users/super.user/Documents/Workspaces/nx-issue-cwd/node_modules/@nx/js/src/executors/node/node.impl.js:79:13)

Node.js v20.12.2
Waiting for the debugger to disconnect...

Package Manager Version

[email protected]

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

⚠ Interesting observation: ⚠

It appears to be related to the workspace root. When printing the fileToRun value here, I'm getting an absolute path in nx@18, but a relative path in nx@20.

nx@18: fileToRun = /Users/super.user/Documents/Workspaces/nx-issue-cwd/dist/services/user-service/main.js

nx@20: fileToRun = dist/services/user-service/main.js

Additionally, when I make this small change in the getFileToRun function on line 407, the issue seems to be resolved.

-       workspaceRoot: '',
+       workspaceRoot: context.root,
@zivadler
Copy link

Super critical for us too

MisterPandaPooh added a commit to MisterPandaPooh/nx that referenced this issue Feb 18, 2025
MisterPandaPooh added a commit to MisterPandaPooh/nx that referenced this issue Feb 18, 2025
@MisterPandaPooh MisterPandaPooh linked a pull request Feb 18, 2025 that will close this issue
MisterPandaPooh added a commit to MisterPandaPooh/nx that referenced this issue Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants