Unable to compile packages because it's not under the rootDir
See original GitHub issueType of Issue
[x] Bug Report
[ ] Feature Request
Description
I have a mono repo that contains an Angular app with a library within it generated by the angular CLI alongside the code for the API and a shared folder for models to be used across both the client and the API
The Library contains services that reference these shared models, however when I go to compile I get the following error;
error TS6059: File '/path/to/mono-repo/models/article/article.model.ts' is not under 'rootDir' '/path/to/mono-repo/angular/projects/core/src'. 'rootDir' is expected to contain all source files.
How To Reproduce
You can reproduce by simply trying to include a file from outside the rootDir that’s automatically generated by ng-packagr.
Here is the folder structure
- angular
-- projects
--- core
---- src
----- lib
------ article
------- article.service.ts
- models
-- article
--- article.model.ts
Expected Behaviour
For the library to compile or for a way to get around this stumbling block.
Version Information
ng-packagr: 3.0.3
@angular/compiler: 6.0.7
rollup: 0.59.4
tsickle: 0.29.0
typescript: 2.7.2
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
'rootDir' is expected to contain all source files - Stack Overflow
'rootDir' is expected tocontain all source files. I have reproduced the error in a sandbox repo on GitHub here.
Read more >File is not under 'rootDir' error in TypeScript | bobbyhadz
The "File is not under 'rootDir'" error occurs when we try to import something from a file that is not located under the...
Read more >TSConfig Reference - Docs on every TSConfig option
Importantly, rootDir does not affect which files become part of the compilation. It has no interaction with the include , exclude , or...
Read more >A guide through The Wild Wild West of setting up a mono repo ...
Before project references, if you changed a package, you needed to re-compile it and also re-check any package depending on it, with no...
Read more >Angular,monorepo,multiple libs and rootDir issue | by Arun Malik
On running “ng build lib1” All we got is this… error TS6059: File '/Users/admin/Desktop/App/libs/lib2/src/util.ts' is not under 'rootDir ...
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
I have the same issue, But I am using a secondary entry point as stated in the secondary-entrypoints.md
The secondary entry point exports its own module which imports a file from the main entry endpoint, building the library throw this error:
BUILD ERROR error TS6059: File 'D:/Projects/ngx-scrollbar/projects/ngx-scrollbar/smooth-scroll/smooth-scroll.module.ts' is not under 'rootDir' 'D:\Projects\ngx-scrollbar\projects\ngx-scrollbar\src' . 'rootDir' is expected to contain all source files.
@alan-agius4 @JoostK How can I fix it?
@MurhafSousli that sounds fine, so you’d need two changes:
You added the following to the public api of
ngx-scrollbar
(the main entrypoint)This is fine, as it is perfectly valid to re-export stuff from dependent entrypoints to become part of your own api surface, however the import specifier needs to become absolute:
This prevents the secondary entrypoint from becoming part of the compilation of the main entrypoint, avoiding the “not in rootDir” error.
Secondly, you added an import from
NgScrollbarModule
in the main entrypoint as follows:This introduces a circular dependency issue, as the
../public-api
file itself has an import into the./lib/ng-scrollbar.module
file, which introduces a cycle. In general, you should never import through the public api within the entrypoint itself, but instead import from the location where the dependency is declared. In your case forSmoothScrollModule
, that would bengx-scrollbar/smooth-scroll
.