question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

library importing other library using wildcard path mapping fails with "is not under 'rootDir'"

See original GitHub issue

Current Behavior

When one library imports from another, I get .../packages/lib1/src/lib/lib1.ts' is not under 'rootDir' 'packages/lib2' Note that this doesn’t happen if an app imports the library in the same way - presumably because an app uses executor @nrwl/node:webpack rather the a library’s @nrwl/js:tsc.

Expected Behavior

library should import. This is a new project, no migration, therefore it’s not the same like https://github.com/nrwl/nx/issues/10785#issuecomment-1159017136.

Steps to Reproduce

  1. Start from scratch:
npx create-nx-workspace badlibs --preset=ts --nxCloud==false
cd badlibs
nx generate @nrwl/js:library --name=lib1 --buildable
nx generate @nrwl/js:library --name=lib2 --buildable
  1. Add the following to tsconfig.base.json:
    "paths": {
      "lib1/*": ["packages/lib1/*"]
    }
  1. Add the following to packages\lib2\src\lib\lib2.ts:
import { lib1 } from 'lib1/src/lib/lib1';
  1. Build all by running: nx affected:build -all --skip-nx-cache

Result:

    ×  nx run lib2:build
       Compiling TypeScript files for project "lib2"...
packages/lib2/src/lib/lib2.ts:1:22 - error TS6059: File 'C:/mono/badlibs/packages/lib1/src/lib/lib1.ts' is not under 'rootDir' 'packages/lib2'. 'rootDir' is expected to contain all source files.

       1 import { lib1 } from 'lib1/src/lib/lib1';

Failure Logs

Environment

   Node : 14.20.0
   OS   : win32 x64
   npm  : 6.14.17

   nx : 14.5.6
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.5.6
   @nrwl/eslint-plugin-nx : 14.5.6
   @nrwl/express : Not Found
   @nrwl/jest : 14.5.6
   @nrwl/js : 14.5.6
   @nrwl/linter : 14.5.6
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/workspace : 14.5.6
   typescript : 4.7.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

2reactions
jonathan-barnercommented, Aug 16, 2022

Looking into nx code, I found a workaround that unblocks this for me. I don’t know enough the nx codebase to say whether this is the actual fix…

edit .\node_modules\@nrwl\js\src\utils\typescript\compile-typescript-files.js After const tscOptions = { add rootDir, so the code looks like this:

        const tscOptions = {
			rootDir: normalizedOptions.root,
0reactions
sebpalluelcommented, Oct 31, 2022

Same issue with this architecture: graph-5

When i do nx run wallet:build it gives me this and a bunch of this kind of error for the other related library:

libs/server/polygon/src/index.ts:2:15 - error TS6059: File '/Users/sebpalluel/Documents/dev/blockchain-wallet/libs/server/polygon/src/lib/polygon.module.ts' is not under 'rootDir' 'libs/server/wallet'. 'rootDir' is expected to contain all source files.

2 export * from './lib/polygon.module';

I’ve tried everything I could but the build is breaking in wallet as if it couldn’t support library nested with a depth that is > 2. When I’m importing the ethers library and moving the code from wallet into nestjs-server it’s working properly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can no longer build publishable libraries that import ... - GitHub
'rootDir' is expected to contain all source files. The file is in the program because: Imported via '@snagajob/cdk/overlay' from file '/Users/ ...
Read more >
Nrwl build Library Error: File is not under rootDir - Stack Overflow
... so I opened nx issue #11583: library importing other library using wildcard path mapping fails with "is not under 'rootDir'".
Read more >
Importing - xmake
Platform extension; Custom task task. The import mechanism is as follows: Import from the current script directory first; Import from the extended class...
Read more >
Working With Files - Gradle User Manual
Let's say you're working on a multi-project build in a dev/projects/AcmeHealth directory. You use the above example in the build of the library...
Read more >
Resolve | webpack
For example, when calling import 'lodash' in ES2015, the resolve options can change where ... Now, instead of using relative paths when importing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found