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

Local plugin executor throws "Cannot find module" error after upgrade to NX 20.3.2 #30132

Open
1 of 4 tasks
Roozenboom opened this issue Feb 21, 2025 · 1 comment · May be fixed by #30133
Open
1 of 4 tasks

Local plugin executor throws "Cannot find module" error after upgrade to NX 20.3.2 #30132

Roozenboom opened this issue Feb 21, 2025 · 1 comment · May be fixed by #30133

Comments

@Roozenboom
Copy link
Contributor

Current Behavior

When we upgrade NX to version 20.3.2 or later our local plugin executors are not working anymore. They throw an error Cannot find module '/Users/roozenboom/Work/npm/nx-examples/tools/workspace/executors/demo'.

Image

The error originates from packages/nx/src/config/schema-utils.ts L30-33:

    if (extname(modulePath) === '.ts') {
      registerPluginTSTranspiler();
    }
    const module = require(modulePath);

After some debugging I found out that the reason for this is that the implementation does not handles index.ts files correctly. All our local plugin executors and generators are configured to use an index.ts file as implementation:

    "demo": {
      "implementation": "./executors/demo",
      "schema": "./executors/demo/schema.json",
      "description": "Executor to demonstrate TS transpile error"
    },

This behavior is introduced by PR 29539, as the TypeScript transpiler is not triggered anymore for our local plugin.

As a workaround i tried to update the implementation to point to the index file directly. This also does not work but throws a different error:
implementation is not a function

    "demo2": {
      "implementation": "./executors/demo/index",
      "schema": "./executors/demo/schema.json",
      "description": "Executor to demonstrate TS transpile error"
    },

Image

Renaming index to something else (for example demo.ts) does not solve this issue.

When I looked at the NX repo and the naming convention you are using for executor implementation, I saw you are using <name>.impl.ts and if i change our implementation to use the same convention it works. Successfully ran target demo3 for project cart

    "demo3": {
      "implementation": "./executors/demo/index.impl",
      "schema": "./executors/demo/schema.json",
      "description": "Executor to demonstrate TS transpile error"
    }

Image

Expected Behavior

The expected behavior is that barrel files (index.ts) are handled correctly and will trigger the TypeScript transpiler when required. It should follow the path as specified in the implementation property of the executors.json and should not depend on an undocumented naming convention.

GitHub Repo

https://github.com/Roozenboom/nx-examples/tree/feature/nx-20-3-2-module-not-found

Steps to Reproduce

I created a minimal reproduction path in nx-examples

  1. Checkout the repo
  2. A local plugin is created in tools/workspace
  3. One simple executor 'demo' is added
  4. In the executors.json we have 3 different implementation for this executor
    a. point to folder "./executors/demo"
    b. point to index file "./executors/demo/index"
    c. point to index.impl file "./executors/demo/index.tmpl"
  5. Add new targets to the cart app to be able to use the executors
  6. Run the targets
    a. yarn nx run cart:demo will throw 'Module not found' error
    b. yarn nx run cart:demo2 will throw 'implementation in not a function' error
    c. yarn nx run cart:demo3 will be successful

Nx Report

Node           : 23.6.1
OS             : darwin-arm64
Native Target  : aarch64-macos
yarn           : 4.2.2

nx                     : 20.4.0-beta.2
@nx/js                 : 20.4.0-beta.2
@nx/jest               : 20.4.0-beta.2
@nx/eslint             : 20.4.0-beta.2
@nx/workspace          : 20.4.0-beta.2
@nx/angular            : 20.4.0-beta.2
@nx/cypress            : 20.4.0-beta.2
@nx/devkit             : 20.4.0-beta.2
@nx/eslint-plugin      : 20.4.0-beta.2
@nx/module-federation  : 20.4.0-beta.2
@nx/react              : 20.4.0-beta.2
@nx/web                : 20.4.0-beta.2
@nx/webpack            : 20.4.0-beta.2
typescript             : 5.7.3
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/cypress/plugin
@nx/jest/plugin
---------------------------------------
Community plugins:
@ngrx/component-store : 19.0.0
@ngrx/effects         : 19.0.0
@ngrx/entity          : 19.0.0
@ngrx/operators       : 19.0.0
@ngrx/router-store    : 19.0.0
@ngrx/store           : 19.0.0
@ngrx/store-devtools  : 19.0.0
---------------------------------------
Local workspace plugins:
	 @nx-example/workspace

Failure Logs

NX   Cannot find module '/Users/roozenboom/Work/npm/nx-examples/tools/workspace/executors/demo'

Require stack:
- /Users/roozenboom/Work/npm/nx-examples/node_modules/nx/src/config/schema-utils.js
- /Users/roozenboom/Work/npm/nx-examples/node_modules/nx/src/command-line/run/executor-utils.js
- /Users/roozenboom/Work/npm/nx-examples/node_modules/nx/src/devkit-internals.js
- /Users/roozenboom/Work/npm/nx-examples/node_modules/nx/src/utils/assert-workspace-validity.js
- /Users/roozenboom/Work/npm/nx-examples/node_modules/nx/src/project-graph/build-project-graph.js
- /Users/roozenboom/Work/npm/nx-examples/node_modules/nx/src/project-graph/project-graph.js
- /Users/roozenboom/Work/npm/nx-examples/node_modules/nx/src/project-graph/file-utils.js
- /Users/roozenboom/Work/npm/nx-examples/node_modules/nx/src/utils/package-manager.js
- /Users/roozenboom/Work/npm/nx-examples/node_modules/nx/src/utils/package-json.js
- /Users/roozenboom/Work/npm/nx-examples/node_modules/nx/src/utils/print-help.js
- /Users/roozenboom/Work/npm/nx-examples/node_modules/nx/src/command-line/run/run.js
- /Users/roozenboom/Work/npm/nx-examples/node_modules/nx/bin/run-executor.js
Pass --verbose to see the stacktrace.

Package Manager Version

No response

Operating System

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

Additional Information

I can provide a fix for this issue by changing the if statement in packages/nx/src/config/schema-utils.ts, because when I instead of checking for extname(modulePath) === '.ts' change this to the helper pluginTranspilerIsRegistered(), the executor is transpiled in all 3 scenarios. But I am not sure this is the best solution for this issue, as I think its maybe better to solve this on a higher level.

@Roozenboom
Copy link
Contributor Author

@AgentEnder I updated the PR with a fix for this root cause of this issue. After more debugging I found the location were it was supposed to call the registerPluginTSTranspiler method.

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.

3 participants