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 find module when executing Generator #13696

Closed
bosycom opened this issue Dec 7, 2022 · 5 comments
Closed

Cannot find module when executing Generator #13696

bosycom opened this issue Dec 7, 2022 · 5 comments
Labels

Comments

@bosycom
Copy link

bosycom commented Dec 7, 2022

Current Behavior

After upgrading to NX 15.3.0 my generators cannot be executed anymore.

Expected Behavior

The generator should be invoked successfully

Github Repo

No response

Steps to Reproduce

Not sure if this is a mistake on my end, so I quickly created a fresh nx workspace to test it out following along https://nx.dev/nx/create-nx-workspace:

yarn create nx-workspace
integrate monorepo
repository name temp
application name tempapp
default stylesheet css

I followed https://nx.dev/recipes/generators/local-generators to create a plugin and generator

npm install @nrwl/nx-plugin@15.3.0
nx g @nrwl/nx-plugin:plugin my-plugin
nx generate @nrwl/nx-plugin:generator my-generator --project=my-plugin

Trying to execute the generator results in an error:

nx generate @temp/my-plugin:my-generator mylib --verbose

Unable to find local plugin [ 'libs\\my-plugin\\src\\index.ts' ] Map(4) {
  'apps/my-plugin-e2e' => 'my-plugin-e2e',
  'apps/tempapp' => 'tempapp',
  'apps/tempapp-e2e' => 'tempapp-e2e',
  'libs/my-plugin' => 'my-plugin'
}

NX   Unable to resolve @temp/my-plugin:my-generator.

   Unable to resolve local plugin with import path @temp/my-plugin

Error: Unable to resolve @temp/my-plugin:my-generator.
Unable to resolve local plugin with import path @temp/my-plugin
    at Workspaces.readGenerator (C:\code\temp\temp\node_modules\nx\src\config\workspaces.js:156:19)
    at Object.<anonymous> (C:\code\temp\temp\node_modules\nx\src\command-line\generate.js:212:92)
    at Generator.next (<anonymous>)
    at fulfilled (C:\code\temp\temp\node_modules\tslib\tslib.js:115:62)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Using TS 4.9.4
Did I miss something or is this really a bug? I noticed that libs/my-plugin/src/index.ts is empty, but maybe that is supposed to be like that!?

Nx Report

Node : 18.12.0
OS   : win32 x64
npm  : 8.19.2

nx : 15.3.0
@nrwl/angular : Not Found
@nrwl/cypress : 15.3.0
@nrwl/detox : Not Found
@nrwl/devkit : 15.3.0
@nrwl/esbuild : Not Found
@nrwl/eslint-plugin-nx : 15.3.0
@nrwl/expo : Not Found
@nrwl/express : Not Found
@nrwl/jest : 15.3.0
@nrwl/js : 15.3.0
@nrwl/linter : 15.3.0
@nrwl/nest : Not Found
Local workspace plugins:
	 @temp/my-plugin
---------------------------------------
Community plugins:

Failure Logs

No response

Additional Information

No response

@FrozenPandaz FrozenPandaz added the scope: core core nx functionality label Dec 7, 2022
@joshmossas
Copy link

This is also happening in our repo as well. NX 15.3.0 cannot resolve our local plugins. We had to revert to a previous version to get it working again.

@mottet
Copy link

mottet commented Dec 13, 2022

Thanks for the workaround. I had the same issue with version 15.3.0. No issue with version 15.2.0.

@mottet
Copy link

mottet commented Dec 15, 2022

After investigation I found that it was a Windows path format related issue. A fix to the problem is already merge #13801 so I guess the issue should be gone in close futur release :)

@bosycom
Copy link
Author

bosycom commented Dec 15, 2022

Thanks @mottet for investigating!

For everyone who cannot wait for the fixed version, you can simply patch the src file in node_modules/nx/src/utils/nx-plugin.js like that which has fixed it for me:

Add new line 14

const { normalizePath } = require("./path");

Change line 134:

const possiblePaths = (_a = tsConfigPaths[importPath]) === null || _a === void 0 ? void 0 : _a.map((p) => normalizePath(path.relative(root, path.join(root, p))));

@bosycom bosycom closed this as completed Dec 15, 2022
@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants