nx icon indicating copy to clipboard operation
nx copied to clipboard

Unable to resolve executor "./dist/packages/semver:version" when depending on "build" target

Open edbzn opened this issue 2 years ago • 1 comments

Current Behavior

Hi there,

In our Nx plugin, we have a "version" target that points to the dist bundle like so:

"version": {
   "executor": "./dist/packages/semver:version"
 }

In nx.json we configured the "version" target to depend on "build", so we ensure that "build" is run before and the dist bundle is populated.

"targetDefaults": {
  "version": {
    "dependsOn": ["build"]
  }
}

Now, running the version executor result in the following error:

 >  NX   Unable to resolve ./dist/packages/semver:version.

   Cannot find module './dist/packages/semver/package.json'
   Require stack:
   - /home/runner/work/semver/semver/node_modules/nx/src/utils/package-json.js
   - /home/runner/work/semver/semver/node_modules/nx/src/utils/package-manager.js
   - /home/runner/work/semver/semver/node_modules/nx/bin/init-local.js
   - /home/runner/work/semver/semver/node_modules/nx/bin/nx.js

Note that it is certainly a regression as it was not happening before 16.1.0.

Expected Behavior

Nx should execute the target dependency before trying to resolve the final executor.

GitHub Repo

https://github.com/jscutlery/semver

Steps to Reproduce

  1. Define a target that references an executor from a dist bundle
  2. Make this target depending on "build" to produce the dist bundle
  3. Run the target, it should fail

Nx Report

Node   : 18.15.0
   OS     : linux x64
   yarn   : 3.6.0
   Hasher : Native
   
   nx                 : 16.3.2
   @nx/js             : 16.3.2
   @nx/jest           : 16.3.2
   @nx/linter         : 16.3.2
   @nx/workspace      : 16.3.2
   @nx/devkit         : 16.3.2
   @nx/eslint-plugin  : 16.3.2
   @nx/plugin         : 16.3.2
   @nrwl/tao          : 16.3.2
   typescript         : 5.0.4
   ---------------------------------------
   Community plugins:
   ngx-deploy-npm : 6.0.0
   ---------------------------------------
   Local workspace plugins:
   	 @jscutlery/semver

edbzn avatar Jun 15 '23 08:06 edbzn

For anyone coming to this issue that is encountering the same problem with their local workspace plugins, the workaround is to point your executor to your local plugin:

"targets": {
   "targetName": {
       "executor": "pluginName:executorName"
    }
}

This usage is detailed in the docs: https://nx.dev/plugins/tutorials/create-plugin#using-your-nx-plugin-locally

Coly010 avatar Jun 15 '23 11:06 Coly010

Still getting an error when pointing to the local plugin:

 >  NX   Cannot find module '/home/runner/work/semver/semver/packages/semver/src/executors/version'

   Require stack:
   - /home/runner/work/semver/semver/node_modules/nx/src/config/workspaces.js
   - /home/runner/work/semver/semver/node_modules/nx/src/command-line/run/run.js
   - /home/runner/work/semver/semver/node_modules/nx/bin/run-executor.js
   Pass --verbose to see the stacktrace.

Failing job in our pipeline. It seems to be an issue with Nx not pointing to the dist bundle.

edbzn avatar Jun 30 '23 08:06 edbzn

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] avatar Dec 28 '23 00:12 github-actions[bot]

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

github-actions[bot] avatar Feb 11 '24 00:02 github-actions[bot]