-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
library importing other library using wildcard path mapping fails with "is not under 'rootDir'" #11583
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
|
The same issue 🥲 |
Facing the same issue. Will go with this solution for the moment. Thank you |
I've tested the below suggestion - got: `Cannot find module 'lib1/src/lib/lib1'`
Setting `"traceResolution": true` I see:
'baseUrl' option is set to 'C:/mono/badlibs', using this value to resolve non-relative module name 'lib1/src/lib/lib1'.
'paths' option is specified, looking for a pattern to match module name 'lib1/src/lib/lib1'.
Module name 'lib1/src/lib/lib1', matched pattern 'lib1/*'.
Trying substitution '../lib1/*', candidate module location: '../lib1/src/lib/lib1'.
Loading module as file / folder, candidate module location 'C:/mono/lib1/src/lib/lib1', target file type 'TypeScript'
So looks like the substitution is treated to start from `baseUrl`. And indeed, setting it to `"lib1/*": ["../badlibs/packages/lib1/*"]` finds the file - but I still get the original error `is not under 'rootDir'`.
From: rbong ***@***.***>
Sent: 2022 Sep 05 11:36 PM
To: nrwl/nx ***@***.***>
Cc: Barner, Jonathan ***@***.***>; Author ***@***.***>
Subject: Re: [nrwl/nx] library importing other library using wildcard path mapping fails with "is not under 'rootDir'" (Issue #11583)
I believe the proper fix is to use the relative path, not path from the root.
So, assuming all of your packages are in packages/* instead of:
"paths": {
"lib1/*": ["packages/lib1/*"]
}
Use:
"paths": {
"lib1/*": ["../lib1/*"]
}
|
I had this issue in one of our monorepo and it was caused by the fact that one of our library's name wasn't valid. We had something like |
I've been fighting with this issue on and off for the last few days - I finally managed to figure the problem for me at least; thought it worth posting here if it helps anyone. Check that your library |
same problem |
Very confusing, but... const { AllCapsulesRegistry } = await import(
'@cfg/all-capsules-registry/lib/AllCapsulesRegistry'
); I managed to remove the error when I changed this import to inline format + // prettier-ignore
const {AllCapsulesRegistry} = await import('@cfg/all-capsules-registry/lib/AllCapsulesRegistry'); Found this by accident. After some tweaking I figured out that what is breaking is a whitespace after the module string and before the closing parenthesis. const { AllCapsulesRegistry } = await import(
'@cfg/all-capsules-registry/lib/AllCapsulesRegistry'); and this does not const {AllCapsulesRegistry} = await import('@cfg/all-capsules-registry/lib/AllCapsulesRegistry' ); // <- single whitespace here `' );` Still confusing, could it be a typescript bug? $ npx nx --version |
Still happens in Any solution for this ? |
https://medium.com/@thearunmalik/angular-monorepo-multiple-libs-and-rootdir-issue-7b8270cbc167 this solution worked for me |
Solution provided by @jonathan-barner worked for me. The only difference, is that for @@ -81,7 +81,7 @@ function getNormalizedTsConfig(options) {
const tsConfig = (0, ts_config_1.readTsConfig)(options.tsConfig);
tsConfig.options.outDir = options.outputPath;
tsConfig.options.noEmitOnError = true;
- tsConfig.options.rootDir = options.rootDir;
+ tsConfig.options.rootDir = '.';
if (tsConfig.options.incremental && !tsConfig.options.tsBuildInfoFile) {
tsConfig.options.tsBuildInfoFile = (0, devkit_1.joinPathFragments)(options.outputPath, 'tsconfig.tsbuildinfo');
} btw, Update: |
I tried this fix in my workspace and a few others I found in similar threads, but none of them solved my problem. What did end up solving my problem was adding
This For whatever reason, this issue only seems to affect a single one of my TypeScript libraries despite having several TS libraries that have dependencies between them. There aren't any circular dependencies, and as far as I can tell, there's nothing special about the one library that's affected by this bug. Edit: Looks like this was actually caused by a few files getting added to my |
related: #11289 This is potentially fixable if you align all the build target names to be the same. For anyone having that error, solution: #17798 (comment) |
Hey all! The original issue in this thread is caused by a mismatch between the TS path mapping and the name of each library in their Following the reproduction steps in the original post (using the latest version instead), the TS path mappings end up with: {
...
"compilerOptions": {
...
"paths": {
"lib1/*": ["lib1/*"],
...
}
}
...
} While the Please note that the Also, note that this error is pretty generic and can occur due to a number of things:
I'm going to close this issue since what was originally reported happened due to a misconfiguration, and this comment explains how to solve it. If you still have issues after following the recommendations here and in the linked issues, please create a new issue with clear steps to reproduce it or better yet, with a reproduction repository so we can troubleshoot it as quickly as possible. |
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. |
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 #10785 (comment).
Steps to Reproduce
tsconfig.base.json
:packages\lib2\src\lib\lib2.ts
:nx affected:build -all --skip-nx-cache
Result:
Failure Logs
Environment
The text was updated successfully, but these errors were encountered: