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.

Unable to compile packages because it's not under the rootDir

See original GitHub issue

Type 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:closed
  • Created 5 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
MurhafSouslicommented, Jul 30, 2019

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?

4reactions
JoostKcommented, Jul 30, 2019

@MurhafSousli that sounds fine, so you’d need two changes:

You added the following to the public api of ngx-scrollbar (the main entrypoint)

export * from '../smooth-scroll/src/public-api';

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:

export * from 'ngx-scrollbar/smooth-scroll';

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:

import { SmoothScrollModule } from '../public-api';

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 for SmoothScrollModule, that would be ngx-scrollbar/smooth-scroll.

Read more comments on GitHub >

github_iconTop 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 >

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