nx: Can't call a library in a plugin from the same workspace

Current Behavior

I can’t use a library in a plugin of the same workspace

Expected Behavior

I should be able to use a library in a plugin of the same workspace

Example: I create a @nrwl/nx-plugin and i want to use its generator in another @nrwl/nx-plugin I create a @nrwl/node library and i want to use its function in a @nrwl/nx-plugin

Steps to Reproduce

Clone this repo Run the following commands:

  • yarn
  • yarn run nx build plugin-app
  • yarn run nx generate ./dist/libs/plugin-app:plugin-app

Failure Logs

@> yarn run nx generate ./dist/libs/plugin-app:plugin-app
yarn run v1.22.5
$ nx generate ./dist/libs/plugin-app:plugin-app
✔ What name would you like to use? · my-app
Cannot find module '@share-generators-over-plugins/plugin-lib'
Require stack:
- /home/arcarox/Documents/test/share-generators-over-plugins/dist/libs/plugin-app/src/generators/plugin-app/generator.js
- /home/arcarox/Documents/test/share-generators-over-plugins/node_modules/@nrwl/tao/src/shared/workspace.js
- /home/arcarox/Documents/test/share-generators-over-plugins/node_modules/@nrwl/tao/src/commands/generate.js
- /home/arcarox/Documents/test/share-generators-over-plugins/node_modules/@nrwl/tao/index.js
- /home/arcarox/Documents/test/share-generators-over-plugins/node_modules/@nrwl/cli/lib/init-local.js
- /home/arcarox/Documents/test/share-generators-over-plugins/node_modules/@nrwl/cli/bin/nx.js
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Environment

@> yarn run nx report
yarn run v1.22.5
$ nx report

>  NX  Report complete - copy this into the issue template

  Node : 12.19.0
  OS   : linux x64
  yarn : 1.22.5
  
  nx : Not Found
  @nrwl/angular : Not Found
  @nrwl/cli : 12.7.0
  @nrwl/cypress : Not Found
  @nrwl/devkit : 12.7.0
  @nrwl/eslint-plugin-nx : 12.7.0
  @nrwl/express : Not Found
  @nrwl/jest : 12.7.0
  @nrwl/linter : 12.7.0
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : 12.7.0
  @nrwl/nx-cloud : Not Found
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 12.7.0
  @nrwl/web : Not Found
  @nrwl/workspace : 12.7.0
  @nrwl/storybook : Not Found
  @nrwl/gatsby : Not Found
  typescript : 4.3.5

Done in 0.32s.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 28 (1 by maintainers)

Most upvoted comments

This should be fixed as part of #9116

🍀🤞

I am also able to reproduce this issue… So it seems we are not able to get all the benefits of a monorepo for plugins which is really a shame 😭

Hey, I’ve been searching for a solution for my issue and i’ve found that the problem don’t seems to be directly link to nx. The error occurs when node try to require the lib using @share-generators-over-plugins/plugin-lib using this logic to find the module (https://nodejs.org/docs/v0.4.2/api/modules.html#all_Together…) . A fix might to update the build executor of plugins to copy the outdir to node_module/${importPath}