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

Angular 5: NPM Link - model/index.ts is not part of the compilation.

Open thaoula opened this issue 9 years ago • 86 comments

Bug Report or Feature Request (mark with an x)

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

Versions.

Angular CLI: 1.5.0 Node: 8.7.0 OS: darwin x64 Angular: 5.0.0

Repro steps.

We have a the following folder structure in a git mono-repo

/api (Express Node App) /model (NPM package using NPM Link, contains mostly typescript interfaces) /web (Angular)

When using Angular 4.46 and Angular CLI 1.5.rc2 and we were able to make reference to the interfaces defined in the model folder using npm link and using the following example import { entity } @app/model

We use ng serve to start the app.

After upgrading Angular to V5 and Angular CLI to 1.5.0 we now get the following error -

The log given by the failure.

Module build failed: Error: /Users/thaoula/Projects/platform/model/index.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.

The occurs for JIT and AOT builds. Running TSC does not result in in errors.

Desired functionality.

Would like be able to build the app using Angular 5

Thanks, Tarek

thaoula avatar Nov 02 '17 02:11 thaoula

I can report a similar issue. Key differences:

  1. I'm not using npm link, I've just installed another git repo via npm with typescript source (ie. original .ts files).
  2. The error I'm getting is: node_modules/other-repo/src/lib/index.ts is not part of the compilation output. Please check the other error messages for details.

Was previously working fine with Angular 4.4.6 and Angular CLI 1.4.7

I'll try to create a minimal repo to reproduce the issue once I get home.

rolaveric avatar Nov 02 '17 05:11 rolaveric

yes i m also faced this issue . angular 5 rc 9 and clic 1.5.0

suresh2018 avatar Nov 02 '17 05:11 suresh2018

me too

xiongyayun428 avatar Nov 02 '17 08:11 xiongyayun428

Same here - without npm link, but with dependencies on typescript libraries in other git repositories

ChristianSchroedel avatar Nov 02 '17 09:11 ChristianSchroedel

I've been testing with several version combinations to flush this out and it seems like it's the CLI causing it. I'm running v1.5.0 with Angular on v5.0.0 final and a similar error shows. Rolling the CLI back to rc8 fixes it.

Then I reverted https://github.com/angular/angular-cli/commit/9b43a9c30420a6fae10de32af90d27c1c0c4d87b manually and the error subsides.

diagramatics avatar Nov 02 '17 10:11 diagramatics

I've found that I only get the problem with ng serve - not with ng build. Specifically: ng build --aot --prod --sourcemaps --stats-json --delete-output-path=false --progress=false

rolaveric avatar Nov 02 '17 10:11 rolaveric

I can confirm what @diagramatics said about rolling back to rc8 working, but I didn't get the same joy from reverting 9b43a9c I also noticed that I get the same error when running ng test (ie. X is not part of the compilation output.) - even with rc8.

rolaveric avatar Nov 02 '17 11:11 rolaveric

Hey all, this is a side effect of the stricter tsconfig as described in https://blog.angular.io/version-5-0-0-of-angular-now-available-37e414935ced#148d.

The tsconfig file is what determines what TS files are compiled. The error you are getting means that the files mentioned are NOT being compiled.

Before we used to compile all files, essentially ignoring what tsconfig listed. This was a bug, because if you don't include a file in the compilation then it should not be compiled.

By default ./src/tsconfig.app.json will only pick up files inside src/. If you have a file outside source, it won't be picked up. But you can add more files to the tsconfig via either files or include.

So for @thaoula's case, you probably want to add this the files in ../models to your tsconfig.app.json and also to your tsconfig.spec.json:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    // ...
  },
  "include": [
    "../models/**/*.ts"
  ],
  "exclude": [
    // ...
  ],
}

You can read more about tsconfig files in https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/tsconfig.json.md.

@rolaveric's case is slightly different. You have TS files in your node_modules. This really goes against how libraries should be packaged: libraries should never ship their source .ts files.

The reason for this rule is that the TypeScript version your app isn't necessarily the same as the TS version your library uses. Different versions of TS can produce different output, and give different errors for the same input. They don't even support the same language features. So packaging libraries with TS sources will always break someone's project.

So we don't really support using incorrectly packaged libraries with TS sources. It's something you do at your risk.

That being said, maybe you can try adding it to the include array. But I can't guarantee that will work in the future because it's still an incorrectly packaged library.

Regarding AOT: as far as I can tell, AOT is still incorrectly compiling TS that is not included in the tsconfig. I'll bring this up with the compiler team. (Edit: reported as https://github.com/angular/angular/issues/20115)

filipesilva avatar Nov 02 '17 13:11 filipesilva

We have the same problem described by @thaoula , but for a file that is located inside the normal tree structure created by the angular-cli. The error occurs with angular 5.0.0 final and angular-cli 1.5. We can "ng serve" the app with angular 5.0.0 and angular-cli 1.4.4.

The file that is not part of the compilation in our project is located at: src/app/core/stateManagement/Models/genericCourse.ts

We never included or excluded files using tsconfig.json so it doesn't seem that the problem comes from the stricker tsconfig usage describeb above. To make sure, I created an empty project using angular-cli 1.5.0 and replaced the tsconfig.json and tsconfig.app.json files in our project with the ones created by the new cli and it didn't solve the problem.

Another thing we have in commun with @thaoula is that the file that is not included in the compilation only contains interface and class definitions. So there might be something with that.

MakesNine avatar Nov 02 '17 15:11 MakesNine

@MakesNine that sounds like a different issue altogether, and one that we thought was fixed. Could you give me a repro of that please?

filipesilva avatar Nov 02 '17 17:11 filipesilva

We are having a similar issue, as well, after upgrading. It is complaining about all of our library packages under node_modules with this same exact error (all packages are installed with NPM so no links). Are we going to have to "include" each package separately in the tsconfig file? This would be a nightmare if its true, now and for maintenance in the future. Is there another solution or something else we can do first before using this new version which obviously breaks us completely?

KevinFernandes avatar Nov 02 '17 19:11 KevinFernandes

@filipesilva I have been trying to reproduce the problem in a small project, but I haven't succeded so far. I will keep trying to isolate the problem to find the source of it.

Here's the exact error I'm getting:

ERROR in ./src/app/core/StateManagement/models/genericCourse.models.ts Module build failed: Error: D:\Projects\LtiisWeb\src\app\core\StateManagement\models\genericCourse.models.ts is not part o f the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at AngularCompilerPlugin.getCompiledFile (D:\Projects\LtiisWeb\node_modules@ngtools\webpack\src\angular_compiler_plug in.js:624:23) at plugin.done.then (D:\Projects\LtiisWeb\node_modules@ngtools\webpack\src\loader.js:467:39) @ ./src/app/+generic-courses/generic-course.component.ts 23:0-84 @ ./src/app/+generic-courses/generic-courses.module.ts @ ./src/$$_lazy_route_resource lazy @ ./node_modules/@angular/core/esm5/core.js @ ./src/main.ts @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts

MakesNine avatar Nov 02 '17 19:11 MakesNine

@MakesNine so if you try having a file with just interfaces it's still fine in a new project? Hm... I've heard of problems with casing. Are your imports perhaps using the wrong casing? Does it still happen if you add a non-interface export to that file? That seems to be a lazy route, perhaps it's related. Can you try making that route not lazy?

@KevinFernandes this definitely shouldn't happen to all library packages, unless somehow you're just using packages that weren't packaged well. Can you give me examples of a couple of these packages? I can have a look.

filipesilva avatar Nov 02 '17 19:11 filipesilva

@filipesilva yest, I can build a new project and import a file with only interfaces from a lazy loaded module. I will double check the casing and try the original app with a non lazy route for the module where the error originates.

MakesNine avatar Nov 02 '17 19:11 MakesNine

@filipesilva I have added an import and exported a function from the file refusing to be part of the compilation and it didn't help. I have changed all the routes, in app-routing.module.ts, that have components importing type definitions from that file so that they wouldn't be lazy loaded and the app compiled, but didn't work. I had forgotten to import the modules, in app.module.ts', that contained the components now used in the non lazy loaded routes. Once I add the required imports in app.module.ts, I get the same problem that I get with lazy loaded routes. I have also checked casing and all seems ok on that front.

MakesNine avatar Nov 02 '17 20:11 MakesNine

Thanks @filipesilva - that explains my issue. I tried explicitly including my internal libraries using include, but that's giving me other grief (picking up on test suites, despite using exclude). So I'll do it properly and have them expose compiled code. I knew it was something I should do, but with them only being used internally by the company, I let it slide.

Thanks again to you and all the contributors for your hard work on Angular CLI - it's an excellent tool and very much appreciated.

rolaveric avatar Nov 02 '17 23:11 rolaveric

I was having the same issue after updating. Like some other people, the ts files were all part of the standard CLI structure tree. Turned out it was a case sensitivity issue for me. I had accidentally written something like...

import { Comment } from './Comment' while in other components import { Comment } from './comment'. Running a normal build would throw me a helpful warning before erroring out, but building for prod only showed me the "Please make sure it is in your tsconfig via the 'files' or 'include' property" error. Fixed the casing issue and prod builds for me fine.

stuartwk avatar Nov 03 '17 01:11 stuartwk

I finally got my app to compile. It turned out that it was a casing issue indeed. The error I was getting was: ERROR in ./src/app/core/StateManagement/models/genericCourse.models.ts

And the solution is to change the related import to: ./src/app/core/stateManagement/models/genericCourse.models.ts

Curiously, I have other files in that folder that were also imported with StateMangement in the path and the compiler didn't complain.

Thansk for your input @filipesilva

MakesNine avatar Nov 03 '17 02:11 MakesNine

We got the same problem when importing the modules.

prasadkadiyala avatar Nov 03 '17 04:11 prasadkadiyala

@MakesNine that is weird indeed, and I'm not really sure why that happens... I expected all bad paths to throw an error somehow. Will keep an eye out for more such casing reports.

filipesilva avatar Nov 03 '17 10:11 filipesilva