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

hello guys, I had the same issue in my project (Angular 5.0.0). I solved it by deleting the file which causes the problem. After i created it again and pasting the same code step by step in order to make sure what part of the code cause the problem. Now everything work. Hope my solution will help you.

@malaba

malaba03 avatar Nov 14 '17 00:11 malaba03

@filipesilva I understand your arguments, but why release a breaking change in a minor version ?!

It's better to add a warning in this version and correct this behaviour in 2.0.0

JulienBourgain avatar Nov 14 '17 11:11 JulienBourgain

If you are working with multiple libraries with npm link under a scope and you have something like the following in your tsconfig:

"paths": { "@my-libs/*": ["../node_modules/@my-libs/*"] }

The error will be present. Remove it

ghost avatar Nov 15 '17 00:11 ghost

Hi , I am also facing the same problem.

while compiling the solution via ng serve -o after angular 5 update this issue occurs.

i have used npm link to link all my modules.

ERROR in ./platform/userModule/app/app.module.ts Module build failed: Error: E:\temp\trunk\platform\userModule\app\app.module.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at AngularCompilerPlugin.getCompiledFile (E:\temp\trunk\node_modules@ngtools\webpack\src\angular_compiler_plugin.js:624:23) at plugin.done.then (E:\temp\trunk\node_modules@ngtools\webpack\src\loader.js:467:39) at @ ./src/$$_lazy_route_resource lazy @ ./node_modules/@angular/core/esm5/core.js @ ./src/main.ts @ multi ./src/main.ts

Jesu26 avatar Nov 15 '17 12:11 Jesu26

i also met the question ,

ERROR in ./src/app/hero.ts Module build failed: Error: F:\lenleeWorkProject\angular\angular-tour-of-heroes\src\app\hero.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 (F:\lenleeWorkProject\angular\angular-tour-of-heroes\node_module s@ngtools\webpack\src\angular_compiler_plugin.js:624:23) at plugin.done.then (F:\lenleeWorkProject\angular\angular-tour-of-heroes\node_modules@ngtools\webpack\sr c\loader.js:467:39) at @ ./src/app/hero-detail/hero-detail.component.ts 11:0-31 @ ./src/app/app.module.ts @ ./src/main.ts @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts

============================ i am check all the hero.ts reference, The discovery problem appears on the file path
is Uppercase the Hero Instead of hero 。

so why path error not prompting?

Instead, it returns to normal after manually triggering the save

Angular CLI: 1.5.0 Node: 8.4.0 OS: win32 x64 Angular: 5.0.1 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router

@angular / cli: 1.5.0 @angular-devkit / build-optimizer: 0.0.33 @angular-devkit / core: 0.0.20 @angular-devkit / schematics: 0.0.35 @ngtools / json-schema: 1.1.0 @ngtools / webpack: 1.8.0 @schematics / angular: 0.1.3 typescript : 2.4.2 webpack : 3.8.1

usernameisMan avatar Nov 16 '17 06:11 usernameisMan

Hello, I came across the same issue using angular 5.0.1 and CLI 1.5 :

Module build failed: Error: xxx\ng4-blog-frontend\src\app\models\post.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.

At first I had a case issue that I solved and it worked fine for a while but the error came back somehow later. I tried what @sandangel suggested by using the flag --preserve-symlinks but it did not worked.

Finally, I found another issue (#20091) where @stephanecot suggested the use of --aot and it works fine, although I have no idea why... As the flag suggests, it use the Ahead of time compilation which can be unwanted.

I hope it will help someone.

abel-bzz avatar Nov 20 '17 14:11 abel-bzz

Tried workarounds mentioned in this thread, dosen't seem to help. Still getting the same error.

ERROR in ./node_modules/angular2-isotope/index.ts

How can I compile the library locally to continue development for the time being?

khalid-halo avatar Nov 23 '17 00:11 khalid-halo

What I did with my library is I moved it to the src folder and included it from there. Not a clean solution, but it'll work until the Angular guys figure this one out.

misaizdaleka avatar Nov 23 '17 11:11 misaizdaleka

FOR ME, The issue comes up when the project stands on a junction directory or symlink.

ghost avatar Nov 24 '17 12:11 ghost

I have same symptoms like @nueko has. When one of my dependencies is linked via symlink and I invoke ng build --prod --build-optimizer - then it fails. --preserve-symlinks helps to fix this particular case: ng build --prod --build-optimizer --preserve-symlinks

rychkog avatar Nov 25 '17 10:11 rychkog

Current set :

Angular-cli : 1.5.4 npm 5.5 node 8.9

This is my problem:

Module build failed: Error: C:\...\src\app\hero.ts is not part of the compilation. 
Please make sure it is in your tsconfig via the 'files' or 'include' property.
  
  at AngularCompilerPlugin.getCompiledFile (C:\...\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:620:23)
    at plugin.done.then (C:\...\node_modules\@ngtools\webpack\src\loader.js:467:39)
    at <anonymous>
 @ ./src/app/hero-details/hero-details.component.ts 11:0-31
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts

milosmijakovac avatar Nov 29 '17 23:11 milosmijakovac

adding: to the defaults section of .angual-cli.json , "build": { "preserveSymlinks": true }

corrects this malfunction. 100% reproducible with generated app.

HollisTech avatar Dec 03 '17 01:12 HollisTech

@HollisTech, or just

ng serve --preserve-symlinks

ghost avatar Dec 03 '17 06:12 ghost

@HollisTech it shows same warning! : ( ERROR in ./src/app/hero.ts ....

milosmijakovac avatar Dec 03 '17 18:12 milosmijakovac

Yep, same issue here with upgrading to 5.1, never had this issue before now.

My include ended up looking like this to bring everything in I needed for compilation.

"include": [ "**.ts", "app/**.ts", "app/**/**.ts", "../node_modules/angular2-semantic-ui/components/**/**.ts" ]

RyannGalea avatar Dec 07 '17 11:12 RyannGalea

We're using the "shared codebase" approach @rolaveric is using and I managed to get it to compile and run fine by adding the following include to the tsconfig.json:

"include": [
    "src/**/*",
    "node_modules/{sharedcodebasename}/**/*"
]

That all works great, however if I try and run ng test I end up with the same build errors that I got before adding our shared codebase to the includes (Module build failed: "{sharedcodebasename}/file.ts" is not part of the compilation output.

Now @filipesilva I appreciate you saying this isn't the "proper way to do an NPM package", but for my case (and what looks like a few others in this thread), we have internal company "packages" that we don't want pushing to NPM (we push them to our private Nexus repo) and publishing typescript files as a package is exactly what we need. Is there any way that this can be resolved? I understand the rationale behind the change in compilation behaviour, but it seems to be causing many unintended headaches.

mattytommo avatar Dec 08 '17 22:12 mattytommo

@mattytommo, instead of editing tsconfig.json like that, you can add the include(s) into tsconfig.app.json + tsconfig.spec.json (prefixed with ../ of course). I know that's slightly uglier. :)

rkrisztian avatar Dec 11 '17 13:12 rkrisztian

@rkrisztian I must have tried it in those files 100 times, but I don't think I actually prefixed with ../ because adding that to the spec.json file works!!

So, essentially, as long as you put the include within the spec.json (for the tests) and the tsconfig.json (or .app.json), the build and tests work. Thanks again rkrisztian.

mattytommo avatar Dec 13 '17 09:12 mattytommo

I don't think is a problem of angular-cli. I compile my projects directly with webpack and my own config files and I have the same problem if a use AOT option with Angular 5.x.x but it's perfect in Angular 4.x.x. But if I don't use AOT option the compilation is fine even in Angular 5.x.x. It's very strange but the problem is that some DTOs classes are not included in the compilation process. I have 15 DTO classes in src\app\common\dto directory and 16 POJO classes in src\app\common\data directory and some of them are not included in the compilation process. I reviewed the Javascript files generated by the AOT compiler and they don't appear in any place. But if I don't use AOT or I use Angular 4.x.x all the classes are included in the compilation process. Maybe the bug is in the Ahead-of-Time compiler in Angular 5.x.x or in the Webpack Plugin: @ngtools\webpack

ERROR in ./src/app/common/dto/SolicitanteDTO.ts Module build failed: Error: G:\Proyectos\BITCITA\bitcita-front\src\main\frontend\src\app\common\dto\SolicitanteDTO.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at AngularCompilerPlugin.getCompiledFile (G:\Proyectos\BITCITA\bitcita-front\src\main\frontend\node_modules@ngtools\webpack\src\angular_compiler_plugin.js:643:23) at plugin.done.then (G:\Proyectos\BITCITA\bitcita-front\src\main\frontend\node_modules@ngtools\webpack\src\loader.js:467:39) @ ./src/app/citas/component/cita-form-new.component.ts 19:23-65 @ ./src/app/citas/cita.module.ngfactory.js @ ./$$_lazy_route_resource async @ ./~/@angular/core/esm5/core.js @ ./src/main-aot.ts

ERROR in ./src/app/common/dto/SolicitanteCampoDTO.ts Module build failed: Error: G:\Proyectos\BITCITA\bitcita-front\src\main\frontend\src\app\common\dto\SolicitanteCampoDTO.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at AngularCompilerPlugin.getCompiledFile (G:\Proyectos\BITCITA\bitcita-front\src\main\frontend\node_modules@ngtools\webpack\src\angular_compiler_plugin.js:643:23) at plugin.done.then (G:\Proyectos\BITCITA\bitcita-front\src\main\frontend\node_modules@ngtools\webpack\src\loader.js:467:39) @ ./src/app/citas/component/cita-form-new.component.ts 18:28-75 @ ./src/app/citas/cita.module.ngfactory.js @ ./$$_lazy_route_resource async @ ./~/@angular/core/esm5/core.js @ ./src/main-aot.ts

ERROR in ./src/app/common/data/reserva.ts Module build failed: Error: G:\Proyectos\BITCITA\bitcita-front\src\main\frontend\src\app\common\data\reserva.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at AngularCompilerPlugin.getCompiledFile (G:\Proyectos\BITCITA\bitcita-front\src\main\frontend\node_modules@ngtools\webpack\src\angular_compiler_plugin.js:643:23) at plugin.done.then (G:\Proyectos\BITCITA\bitcita-front\src\main\frontend\node_modules@ngtools\webpack\src\loader.js:467:39) @ ./src/app/recursos/component/agenda-form-reserva-list.component.ts 8:16-52 @ ./src/app/recursos/component/agenda-form.component.ngfactory.js @ ./src/app/campanyas/campanya.module.ngfactory.js @ ./$$_lazy_route_resource async @ ./~/@angular/core/esm5/core.js @ ./src/main-aot.ts

estebanluengo avatar Dec 13 '17 12:12 estebanluengo

I have faced the same issue and turns out, in my case it was a Casing Issue.

I had an import like so: import { Employee } from '../../../models/employeeType.model'; in more than one component.

One of the components that had this import had a different casing in the file path like import { Employee } from '../../../models/EmployeeType.model';

Changing the file path for the import to be consistent across the application fixed the issue for me.

rgantla avatar Dec 13 '17 20:12 rgantla