nrwl/nx

runExecutor does not run buildTarget using @nx/js:node executor

nicky-lenaers-phoenicks opened this issue ยท 3 comments

Current Behavior

I have a serve target as follows:

"serve": {
  "executor": "@nx/js:node",
  "defaultConfiguration": "development",
  "options": {
    "buildTarget": "app:build"
  }
}

The executor of the build target is irrelevant. When I run this target through nx run app:serve it first builds the app using the above buildTarget set to app:build and then serves the Node app.

However, when I run the following code from inside a custom executor the buildTarget of the above serve target is never executed:

await runExecutor(
  { project: 'app', target: 'serve' },
  {},
  context,
);

This results in the following error:

throw new Error(`Could not find ${fileToRun}. Make sure your build succeeded.`);

Expected Behavior

When running a target with executor @nx/js:node programmatically through runExecutor() it should execute buildTarget before serving the Node app.

GitHub Repo

No response

Steps to Reproduce

  1. Create an Nx app with a Node backend
  2. Add a serve target (see above)
  3. Add a custom executor and use the runExecutor() function to trigger the serve target (see above)

Nx Report

Node   : 20.12.0
OS     : linux-arm64
npm    : 10.5.0

nx                 : 19.0.2
@nx/js             : 19.0.2
@nx/jest           : 19.0.2
@nx/linter         : 19.0.2
@nx/eslint         : 19.0.2
@nx/workspace      : 19.0.2
@nx/angular        : 19.0.2
@nx/cypress        : 19.0.2
@nx/devkit         : 19.0.2
@nx/eslint-plugin  : 19.0.2
@nx/nest           : 19.0.2
@nx/node           : 19.0.2
@nx/plugin         : 19.0.2
@nrwl/tao          : 19.0.2
@nx/web            : 19.0.2
@nx/webpack        : 19.0.2
nx-cloud           : 18.0.1
typescript         : 5.4.3
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/jest/plugin
@nx/cypress/plugin
@nx/webpack/plugin
---------------------------------------
Community plugins:
@ngrx/component-store  : 17.1.1
@ngrx/effects          : 17.1.1
@ngrx/entity           : 17.1.1
@ngrx/router-store     : 17.1.1
@ngrx/schematics       : 17.1.1
@ngrx/store            : 17.1.1
@ngrx/store-devtools   : 17.1.1
@nx-tools/nx-container : 6.0.0
apollo-angular         : 6.0.0
---------------------------------------
Local workspace plugins:
         @org/my-plugin

Failure Logs

throw new Error(`Could not find ${fileToRun}. Make sure your build succeeded.`);

Package Manager Version

NPM 10.5.0

Operating System

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

Additional Information

No response

Experiencing the same on Nx 19.0.3:

Node   : 20.12.2
OS     : win32-x64
pnpm   : 8.15.8

nx                 : 19.0.3
@nx/js             : 19.0.3
@nx/jest           : 19.0.3
@nx/eslint         : 19.0.3
@nx/workspace      : 19.0.3
@nx/eslint-plugin  : 19.0.3
@nx/nest           : 19.0.3
@nx/node           : 19.0.3
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/jest/plugin
@nx/jest/plugin

Manually running build and then serving does work.

I am not sure how your executor was created but this is working for me.

Here is a repro: https://github.com/ndcunningham/custom-executor
You can read more about custom executors: https://nx.dev/extending-nx/recipes/local-executors

Feel free to check us on discord if you need additional help.

Hi @ndcunningham , thanks for checking this issue. I cloned your repository and tried running the custom executor, but I still get the original issue. This is the full output after running npx nx run acme:echo in your repo:

node โžœ /workspaces/custom-executor (main) $ npx nx run acme:echo

> nx run acme:echo

Executing "myExecutor"...
/workspaces/custom-executor/node_modules/@nx/js/src/executors/node/node.impl.js:306
    throw new Error(`Could not find ${fileToRun}. Make sure your build succeeded.`);
          ^

Error: Could not find dist/apps/acme/main.js. Make sure your build succeeded.
    at fileToRunCorrectPath (/workspaces/custom-executor/node_modules/@nx/js/src/executors/node/node.impl.js:306:11)
    at /workspaces/custom-executor/node_modules/@nx/js/src/executors/node/node.impl.js:99:49
    at new Promise (<anonymous>)
    at Object.start (/workspaces/custom-executor/node_modules/@nx/js/src/executors/node/node.impl.js:93:36)
    at Timeout.processQueue [as _onTimeout] (/workspaces/custom-executor/node_modules/@nx/js/src/executors/node/node.impl.js:64:13)

Node.js v22.1.0

โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”

 NX   Ran target echo for project acme (4s)

   โœ–  1/1 failed
   โœ”  0/1 succeeded [0 read from cache]

I run my app inside a Dev Container. I tried both Node 20 and Node 22 but neither works. My .devcontainer/devcontainer.json looks like this:

{
    "name": "development",
    "image": "mcr.microsoft.com/devcontainers/typescript-node:22"
}

I am on MacOS Sonoma 14.4.1 (23E224).

Can you have another look? At the rist of being obvious, please make sure you did not build the project before serving (if so, remove the dist), because that picks up the built files without throwing the error.

Thank you!