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

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

30 Answers

✔️Accepted Answer

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 angular/angular#20115)

Other Answers:

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.

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.

I have this issue....this issue sucks :(

this is how I solved it for local development:

https://stackoverflow.com/questions/48797135/missing-ts-files-due-to-npm-link/48798373#48798373

I don't know if people are still having this problem - here's how I fixed the issue.

I have 2 tsconfig.json files, one at the root of the app, and the other inside the src folder (one level down from the root) named tsconfig.app.json that extends the main tsconfig.json. I explicitly added the package that I needed that wasn't being transpiled by Typescript in the "include" array, and like a lot of people here I was getting the *.spec.ts files included despite having them in "exclude" option, so I removed it from the tsconfig.json. The fix was adding the "exclude" option to the second (extended) tsconfig.app.json file. Doing that fixes the Typescript errors and lets me run ng serve without issue.

Here is tsconfig.json:

{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src",
"outDir": "./dist",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
},
"include": [
"./src",
"node_modules/your_package"
]
}

And tsconfig.app.json:

{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../dist",
"baseUrl": "./",
"module": "es2015",
"types": []
},
"exclude": [
"../node_modules/your_package/**/*.spec.ts"
]
}

For some reason adding the exclude in the extended tsconfig (tsconfig.app.json) file is the only way I was able to get it to not complain about the spec files.

Based on the comments from @filipesilva this may still be a bug but it worked for me. Hopefully this helps anyone facing the same issue.

Related Issues:

286
angular cli Issue: Cannot read property 'thisCompilation' of undefined
Here is the answer from issues #9793 : npm remove webpack npm install webpack@3.11.0 ...
255
angular cli Error | Could not find plugin "proposal-numeric-separator" | Generating ES5 bundles for differential loading
Try to install @babel/compat-data: ~7.8.0 to devDependencies This is the only workaround which helpe...
236
angular cli Using invalid environment causes error in build (was "ERROR in Cannot read property 'length' of undefined")
Probably not the same cause but we had the same error (Cannot read property 'length' of undefined) w...
232
angular cli ng serve method ip not open in another machines
The solution is simple Just bind to the correct interface address via ng serve --host=0.0.0.0 ...
226
angular cli Incorrect JS paths when ng build -prod is deployed in a subfolder
When you're deploying to non-root path within a domain you'll need to manually update the <base href...
218
angular cli Installation error: permission denied for node-sas
sudo npm install -g --unsafe-perm --verbose @angular/cli Installation error (node-sass) with: node v...
208
angular cli ng build -prod Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
Instead of use ng build --prod use ng build --env=prod UPDATE As many of us (thx) have mention this ...
173
angular cli Property 'controls' does not exist on type 'AbstractControl'.
Got it! Looked at the docs - FormArray The FormArray class contains the controls property ...
167
angular cli [Bug] cli needs to be reloaded when a lazy loaded module is added in routes (FIXED)
I recomended change { path: 'user-panel' loadChildren: './user-panel/user-panel.module#UserPanelModu...
162
angular cli AOT build fails
I noticed same problem and after npm i enhanced-resolve@3.3.0 I can build with AOT ...
161
angular cli Cannot find name 'require'. using relative paths...
Ahhh here we go try adding declare var require: any; To src/typings.d.ts I am using a config with re...
146
angular cli "No NgModule metadata found for 'AppModule'" after Upgrade to Angular 5.1.0 and AngularCli 1.6.0
I got the same error The issue is fixed only when i manually re installed angular/cli The webpack sh...
141
angular cli ng serve doesn't listen other than localhost
Works with command ng serve --host 0.0.0.0 OS? Windows 7 8 or 10 Linux (which distribution) Mac OSX ...
125
angular cli ng: command not found
Removing NODE and using NVM instead fixed a lot of issues After installing angular-cli with the help...
125
angular cli ng build fails with error Cannot find module 'webpack/lib/node/NodeTemplatePlugin' after updating to v1.3.0
I faced this issue many times recently and always the fix worked for me is : Bug Report or Feature R...
124
angular cli -bash: ng: command not found
This was a pain to figure out Please provide us with the following information: OS? Mac OSX (Seirra)...
124
angular cli Uncaught TypeError: Cannot read property 'apply' of undefined on new install
Downgraded to zone.js@0.8.5 and the problem disappeared. Bug Report or Feature Request (mark with an...
122
angular cli I am on Angular 5 and CLI 1.5 and I get an error
I faced this error after updating a non-CLI project to Angular 5 and @ngtools/webpack 1.8.0 ...
114
angular cli Error in multi styles
Paths in angular-cli.json are relative to the project root (src/ normally) For instance you have the...
107
angular cli Error loading npm linked custom library with aot
It seems like this is a issue caused by Typescript and not by Angular CLI Typescript has problems re...
97
angular cli Cannot find module '@angular/compiler-cli' when running ng serve
Remove angular-cli from your package.json and replace it with @angular/cli $ npm uninstall angular-c...
93
angular cli patterns.map is not a function
I have same issue Finally It looks like caused by a scheme changing The item assets now is an array ...
92
angular cli ng test ends with "Executed 0 of 0 ERROR"
#2125 see @jtsom 's answer: In the karma.conf.js file add: mime: { 'text/x-typescript': ['ts','tsx']...
91
angular cli Error while installing @angular/cli on AWS Ubuntu 16.04 server
This seems to be a problem with installing https://github.com/sass/node-sass which is one of the dep...
89
angular cli Existing App does not get Service Worker capabilities
I also had this issue the culprit seams to be angularFire2 I worked around it by registering the ser...
85
angular cli -Webkit-Line-Clamp Not Working in Angular 6
@briantq can you try this? I took it from here I'm submitting a.. Current behavior In Angular 5 ...
82
angular cli error TS2554: Expected 2 arguments, but got 1 in v8
Before: @ViewChild('foo') foo: ElementRef; After: // query results available in ngOnInit @ViewChild(...
79
angular cli SCSS "Module not found: Error: Can't resolve" for @font-face url with relative path
Searched around and apparently this is just how sass loader works: sass/sass#1015 There's a suggesti...
79
angular cli Lazy loading module broken with " No module factory available for dependency type: ContextElementDependency"
fixed : npm uninstall --save-dev webpack sudo rm -R node_modules npm install i think its not lazy lo...
77
angular cli Angular-cli 6 and base-href no longer supported?
hi thanks for you hint Versions Repro steps change index.html e.g ...
77
angular cli An unhandled exception while Generating ES5 bundles
I was able to fix my build by for the moment changing the tsconfig.app.json target from es2015 back ...
77
angular cli Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
npm install enhanced-resolve@3.3.0 Did the trick for me Bug Report or Feature Request (mark with an ...
77
angular cli Angular 5: NPM Link - model/index.ts is not part of the compilation.
Hey all this is a side effect of the stricter tsconfig as described in https://blog.angular.io/versi...
76
angular cli vendor.bundle.js size is around 10 MB
What command did you run to get these results? ng build by itself does not have any optimizations ...
75
angular cli How to run jasmine tests without browser ?
Here is how I did it Then I modified the plugins property of the karma.conf.js file adding the Phant...
75
angular cli Error: dryRunSink.commit(...).ignoreElements(...).concat is not a function
Following this worked - Just Upgraded to Angular CLI: 1.6.4 each time I run ng new I get this error ...
73
angular cli ProgressPlugin breaks with webpack 4.25.* due to incorrect option colors
Can be fixed temporarily by adding this line to package.json then npm install ...
73
angular cli Bootstrap styles not loading
I think it is because of the problem with bootstrap try this: Step 1 Hi ...
71
angular cli Repository is not clean after cli/core update
FYI there is an allow-dirty flag to bypass the repo check. 🐞 Bug report Command (mark with an x) Is...
70
angular cli ng add @angular/pwa doesn't work correctly in angular-cli 6.2.5 (Maximum call stack size exceeded)
Currently you will need to execute ng add @angular/pwa@v6-lts to ensure the version compatible with ...
69
angular cli Cannot find module '@angular/tsc-wrapped/src/tsc'
@iaashish i was facing issue - tried following and it worked reinstalled npm to latest version npm u...
68
angular cli --build-optimizer errors "Cannot read property 'type' of undefined"
I had a similar problem and solved it by replacing import { Observable } from 'rxjs/Rx'; with import...
67
angular cli ng update did not change my import statements
A workaround for now is to run the following commands after you are already on Angular and CLI versi...
66
angular cli Can't install angular-cli globally
Try to clean cache npm cache clean uninstall angular-cli npm uninstall -g angular-cli & install agai...
66
angular cli Error: Module not found: Error: Can't resolve 'fs'
You can fix it just add to the package.json Bug Report or Feature Request (mark with an x) Versions ...
64
angular cli tsconfig paths and module resolution errors in VS Code
@mehs2690 can you type environment in editor ( don't add import statement yet ) and then press Ctrl ...
64
angular cli Error on update to Webpack 4.0.1
@DanPride I had the same issue made the same mistake of upgrading webpack independently ...
63
angular cli Creating new component shows error:TypeError: core_1.PriorityQueue is not a constructor
I had the same issue and solved it by adding devkit-core in version 0.0.29 to my devDependencies or ...
62
angular cli ng-serve is not working - Could not find module "@angular-devkit/build-angular"
@DineshChopra i've finally made this npm install @angular-devkit/build-angular and it worked I'm won...
61
angular cli Allowing different HOST headers to be used in ng serve
@ryanper in that example you have the same IP address used for --host and --public-host? If that's t...