nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.29k stars 2.32k forks source link

require() of ES Module executor.js ... not supported with custom plugin using es2015 module #16776

Closed vneogi199 closed 1 year ago

vneogi199 commented 1 year ago

Current Behavior

When using a custom NX plugin which has been built with es modules, I get the error: require() of ES Module executor.js ... not supported.

When using "module": "commonjs", it works without issue.

From the stacktrace issue seems to be because we are using require here: https://github.com/nrwl/nx/blob/16.0.x/packages/nx/src/config/workspaces.ts#L336.

It would be great to have es modules supported as well in addition to commonjs.

Expected Behavior

User should be able to use plugin executors with es modules.

GitHub Repo

https://github.com/vneogi199/nx-examples/tree/es-module-plugin-issue

Steps to Reproduce

  1. Create an NX plugin.
  2. Create an executor within it.
  3. For the plugin's tsconfig.json, change "module" to "es2015".
  4. Make a build.
  5. Use this built plugin executor within another NX project.
  6. Run this NX task. Error thrown: require() of ES Module executor.js ... not supported

Nx Report

Node   : 19.9.0
   OS     : linux x64
   yarn   : 1.22.19
   Hasher : Native

   nx                 : 16.1.0-rc.0
   @nx/js             : 16.1.0-rc.0
   @nx/jest           : 16.1.0-rc.0
   @nx/linter         : 16.1.0-rc.0
   @nx/workspace      : 16.1.0-rc.0
   @nx/angular        : 16.1.0-rc.0
   @nx/cypress        : 16.1.0-rc.0
   @nx/devkit         : 16.1.0-rc.0
   @nx/eslint-plugin  : 16.1.0-rc.0
   @nx/plugin         : 16.1.0-rc.0
   @nx/react          : 16.1.0-rc.0
   @nrwl/tao          : 16.1.0-rc.0
   @nx/web            : 16.1.0-rc.0
   @nx/webpack        : 16.1.0-rc.0
   nx-cloud           : 16.0.5
   typescript         : 5.0.4
   ---------------------------------------
   Community plugins:
   @ngrx/component-store : 15.3.0
   @ngrx/effects         : 15.3.0
   @ngrx/entity          : 15.3.0
   @ngrx/router-store    : 15.3.0
   @ngrx/store           : 15.3.0
   @ngrx/store-devtools  : 15.3.0
   @nx-example/my-plugin : 0.0.1

Failure Logs

No response

Operating System

Additional Information

No response

AgentEnder commented 1 year ago

ESM support for Nx plugins is tracked here: https://github.com/nrwl/nx/issues/15682

Its not a small effort and we don't currently have any updates, but it is on our radar. Stay tuned. 📺

github-actions[bot] commented 1 year ago

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.