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

Nx v.12 cannot build libs that depend on other libs #6443

Closed
gerardcastell opened this issue Jul 21, 2021 · 3 comments
Closed

Nx v.12 cannot build libs that depend on other libs #6443

gerardcastell opened this issue Jul 21, 2021 · 3 comments
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug

Comments

@gerardcastell
Copy link

gerardcastell commented Jul 21, 2021

Current Behavior

When running Nx build with Nx v12 and Angular v12 the builder is not able to find assets from another libs, it is like the relative path ("import {whatever} from '@relative-path'") to foreign libs is broken. It appears a lot of different errors but the main reason is that error. Some examples of that errors are:
File 'folder/file.ts' is not under 'rootDir' 'libs/anotherLib/component 'rootDir' is expected to contain all source files.

Expected Behavior

When using the previous versions, the aforementioned error does not appear and the builder completed successfully.

Steps to Reproduce

I have built a simple repository that reproduces the same error and you can clone: https://github.com/gerardcastell/nx-monorepo-libs-deps I have created it with the 'npx create-nx-workspace@latest' command and selecting an Angular framework. After that, I added 3 libs using the command 'nx g @nrwl/angular:lib lib-name --directory=core --buildable' and on of the make it publishable to check if there is any difference but I was not able to find out any one. One lib is a ngrx store "core-data-access-store", which imports another lib "core-environments" which is a simple module that exports a file 'environments.ts' (the publishable lib works the same way that core-environments, it was just a test but is not used). So at this point we have two dependencies: Lab-app -> core-data-access-store -> core-environments. As I read on your book "enterprise-angular-mono-repo-patterns" I consider that the architecture follows your advices, if does't please feel free to explain me how I should do it, I will be very thankful!

Failure Logs

If you clone the repo and install the dependencies you may proceed to build the app or even the core-data-access-store. As it depends on the core-environment you will see that this package builds as expected but the core-data-access-store is failing and the following error appears:

Screenshot 2021-07-21 at 10 28 39

This type of error is what appear on every lib that has imports in our enterprise repository.
We found a valid workaround but it is pretty nasty: https://medium.com/@thearunmalik/angular-monorepo-multiple-libs-and-rootdir-issue-7b8270cbc167
In fact, you may find in the repository that I share with you the wrapper_index.ts, which follows the workaround and It works perfectly when we change the entryFile of the ng-package.json pointing to the wrapper the build works:
Screenshot 2021-07-21 at 10 33 59

Screenshot 2021-07-21 at 10 33 34

Screenshot 2021-07-21 at 10 48 48

Some issues and links that we have check and seems to be related but do not work for us are linked below:
ng-packagr/ng-packagr#987
#2955
#1765
#2794
https://stackoverflow.com/questions/48189713/visual-studio-shared-typescript-library-ts6059-file-is-not-under-rootd
ng-packagr/ng-packagr#1264

Environment

`Report complete - copy this into the issue template

Node : 12.22.1
OS : darwin x64
npm : 6.14.12

nx : Not Found
@nrwl/angular : 12.5.8
@nrwl/cli : 12.5.8
@nrwl/cypress : 12.5.8
@nrwl/devkit : 12.5.8
@nrwl/eslint-plugin-nx : 12.5.8
@nrwl/express : Not Found
@nrwl/jest : 12.5.8
@nrwl/linter : 12.5.8
@nrwl/nest : 12.5.8
@nrwl/next : Not Found
@nrwl/node : 12.5.8
@nrwl/nx-cloud : 12.2.7
@nrwl/react : Not Found
@nrwl/schematics : Not Found
@nrwl/tao : 12.5.8
@nrwl/web : Not Found
@nrwl/workspace : 12.5.8
@nrwl/storybook : 12.5.8
@nrwl/gatsby : Not Found
typescript : 4.2.4`

Any help is welcome, thank you for your time!

@gerardcastell gerardcastell changed the title Nx v.12 cannot build libs which depends on other libs Nx v.12 cannot build libs which depend on other libs Jul 21, 2021
@leosvelperez leosvelperez added the scope: angular Issues related to Angular support in Nx label Jul 21, 2021
@gerardcastell gerardcastell changed the title Nx v.12 cannot build libs which depend on other libs Nx v.12 cannot build libs that depend on other libs Jul 21, 2021
@leosvelperez
Copy link
Member

This was solved in #6429 and it's now available in Nx 12.6.0.

@gerardcastell
Copy link
Author

I have taken a glance at your update an it is NOT working if I run the migration to the latest version. The error keeps the same.
Steps to reproduce:
Environemnt:

Node : 12.22.1
OS : darwin x64
npm : 6.14.12

nx : Not Found
@nrwl/angular : 12.5.8
@nrwl/cli : 12.5.8
@nrwl/cypress : 12.5.8
@nrwl/devkit : 12.5.8
@nrwl/eslint-plugin-nx : 12.5.8
@nrwl/express : Not Found
@nrwl/jest : 12.5.8
@nrwl/linter : 12.5.8
@nrwl/nest : 12.5.8
@nrwl/next : Not Found
@nrwl/node : 12.5.8
@nrwl/nx-cloud : 12.2.7
@nrwl/react : Not Found
@nrwl/schematics : Not Found
@nrwl/tao : 12.5.8
@nrwl/web : Not Found
@nrwl/workspace : 12.5.8
@nrwl/storybook : 12.5.8
@nrwl/gatsby : Not Found
typescript : 4.2.4

  1. Git clone the repository aforementioned https://github.com/gerardcastell/nx-monorepo-libs-deps
  2. Run "nx migrate latest"
  3. Run "npm i"
  4. Run "nx migrate --run-migrations"
  5. Finally, run "nx build"

The error displayed on the console is the same one:
Screenshot 2021-07-27 at 11 53 57

The resulting environment properties now are:
Node : 12.22.1
OS : darwin x64
npm : 6.14.12

nx : Not Found
@nrwl/angular : 12.6.2
@nrwl/cli : 12.6.2
@nrwl/cypress : 12.6.2
@nrwl/devkit : 12.6.2
@nrwl/eslint-plugin-nx : 12.6.2
@nrwl/express : Not Found
@nrwl/jest : 12.6.2
@nrwl/linter : 12.6.2
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/nx-cloud : Not Found
@nrwl/react : Not Found
@nrwl/schematics : Not Found
@nrwl/tao : 12.6.2
@nrwl/web : Not Found
@nrwl/workspace : 12.6.2
@nrwl/storybook : 12.6.2
@nrwl/gatsby : Not Found
typescript : 4.3.5

What I realised is that if I create a new repository with the command "npx create-nx-workspace@latest" and then perform the same steps than before, the error is now happening anymore, so I think that the error here is solved for new projects but not for already existing ones that needs the migration step to get the Nx 12.6.0 version.

Could you please check my case and consider reopen this issue?
Thank you in advance!

@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 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug
Projects
None yet
Development

No branches or pull requests

2 participants