angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

'rootDir' is expected to contain all source files

Open samherrmann opened this issue 8 years ago • 8 comments

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

node --version: 8.9.0

npm -v: 5.6.0

ng -v:

Angular CLI: 6.1.3
Node: 8.9.4
OS: linux x64
Angular: 6.1.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.6.8
@angular-devkit/build-angular      0.6.8
@angular-devkit/build-ng-packagr   0.7.3
@angular-devkit/build-optimizer    0.6.8
@angular-devkit/core               0.6.8
@angular-devkit/schematics         0.7.3
@angular/cli                       6.1.3
@ngtools/json-schema               1.1.0
@ngtools/webpack                   6.0.8
@schematics/angular                0.7.3
@schematics/update                 0.7.3
ng-packagr                         3.0.6
rxjs                               6.2.2
typescript                         2.9.2
webpack                            4.8.3

Repro steps

  1. Clone https://github.com/samherrmann/angular-sandbox
  2. Checkout rootDir-expect-all-source-files-error branch
  3. Run npm install
  4. Run npm run build

The log given by the failure

error TS6059: File '/code/projects/bar/src/lib/types.ts' is not under 'rootDir' '/code/projects/foo/src'. 'rootDir' is expected to contain all source files.

Error: error TS6059: File '/code/projects/bar/src/lib/types.ts' is not under 'rootDir' '/code/projects/foo/src'. 'rootDir' is expected to contain all source files.

    at Object.<anonymous> (/code/node_modules/ng-packagr/lib/ngc/compile-source-files.js:53:68)
    at Generator.next (<anonymous>)
    at /code/node_modules/ng-packagr/lib/ngc/compile-source-files.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/code/node_modules/ng-packagr/lib/ngc/compile-source-files.js:3:12)
    at Object.compileSourceFiles (/code/node_modules/ng-packagr/lib/ngc/compile-source-files.js:19:12)
    at Object.<anonymous> (/code/node_modules/ng-packagr/lib/ng-v5/entry-point/ts/compile-ngc.transform.js:26:32)
    at Generator.next (<anonymous>)
    at /code/node_modules/ng-packagr/lib/ng-v5/entry-point/ts/compile-ngc.transform.js:7:71
    at new Promise (<anonymous>)

Desired functionality

I would expect the build to be successful. I am not sure at this point if this is a tsconfig issue, or a tsc issue, or some other issue.

Mention any other details that might be useful

I also asked this on StackOverflow

samherrmann avatar Aug 14 '18 23:08 samherrmann

This looks like the problem that is occurring due to the import types which was introduced in TypeScript 2.9. When emitted these are not being rewired properly see line 3.

dist/bar/lib/bar.component.d.ts(5,11):

export declare class BarComponent implements OnInit {
    private barService;
    list: import("projects/bar/src/lib/types").Item[]; 
    constructor(barService: BarService);
    ngOnInit(): void;
}

In the above emitted dts, list: import("projects/bar/src/lib/types").Item[]; should be something like import("./types").Item[]; instead.

A workaround for this can be that from your code instead infering the type, you explicitly set it.

in bar.component.ts change the below;

  list = this.barService.list();

to:

  list: Item[] = this.barService.list();

This will remove the type import and the consuming library will build.

I also checked a bit with future versions of TypeScript, it is still an issue in TypeScript 3.0.1, but it looks like it has been addressed in dev version of TypeScript 3.1.0, ie 3.1.0-dev.20180813

alan-agius4 avatar Aug 15 '18 09:08 alan-agius4

nice analysis, thanks @alan-agius4 ! I hadn't seen how they fixed the "type cannot be named" issue that was so confusing with the --declaration flag. Is there a corresponding issue on the TS repo?

Looks like there is nothing for us to do here?

alexeagle avatar Aug 15 '18 13:08 alexeagle

Indeed those errors used to be confused.

TS issue should be: https://github.com/Microsoft/TypeScript/issues/25685

I don’t think there is anything that Angular nor ng-packagr can do.

alan-agius4 avatar Aug 15 '18 13:08 alan-agius4

@alexeagle, @alan-agius4 many thanks for helping me trace this down!

samherrmann avatar Aug 15 '18 13:08 samherrmann

I wanted to check this really considered fixed? I have two publishable libraries (using nrwl) and facing the same problem my version of devkit/core : "@angular-devkit/core": "^0.8.5",

fkolar avatar Nov 21 '18 11:11 fkolar

Note that I was playing with Angular elements like a monkey (and angular libs as a consequence) and got this error by importing stuff from the main app into the lib.

hint: don't do this, element dependencies should come through the component's inputs.

ruimarques avatar Dec 12 '18 11:12 ruimarques

tsc alone seems to work and trans-pile code fine. So there must be something with angular/cli or ng-packagr (for me) otherwise makes no sence.

Rambou avatar Mar 08 '19 08:03 Rambou

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.