Nrwl build Library Error: File is not under rootDir

Viewed 199

The error occurs when I use the library in another library. Library import is working fine in the app but not working within libraries. And not able to generate the build of a library. All libraries are publishable.

Error:

Error

Nrwl.v13 Files Structure within lib folder:

Nrwl.v13 Files Structure within lib folder

2 Answers

Very difficult to debug. It can be related to circular dependency issue. Are you sure you don't import code from library which import code from the same library ? A import B B import A

If this is the case, you should handle this by creating a C library which will be imported by A and B or find a solution for the A or B which will not depend on each other.

Code example will be helpful for help you.

From https://github.com/nrwl/nx/issues/10785#issuecomment-1158916416:

There seems to have been an issue with a migration that was scheduled for a version but the migration itself was released in another version, so that might have caused the migration to not run in some scenarios. That migration should have added the following in nx.json for anyone having their nx.json extending from nx/presets/core.json or nx/presets/npm.json:

{
  ...
  "pluginsConfig": {
    "@nrwl/js": {
      "analyzeSourceFiles": true
    }
  }
}

Could you please add the above snippet to your nx.json and try again? If after applying the change it doesn't pick it up immediately, run nx reset and then try again.

This didn't work for me though, so I opened nx issue #11583: library importing other library using wildcard path mapping fails with "is not under 'rootDir'"

Related