library importing other library using wildcard path mapping fails with "is not under 'rootDir'"
See original GitHub issueCurrent 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
- 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
- Add the following to
tsconfig.base.json
:
"paths": {
"lib1/*": ["packages/lib1/*"]
}
- Add the following to
packages\lib2\src\lib\lib2.ts
:
import { lib1 } from 'lib1/src/lib/lib1';
- 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:
- Created a year ago
- Reactions:4
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
Afterconst tscOptions = {
addrootDir
, so the code looks like this:Same issue with this architecture:
When i do
nx run wallet:build
it gives me this and a bunch of this kind of error for the other related library: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 theethers
library and moving the code fromwallet
intonestjs-server
it’s working properly.