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

@rgantla wooww..I wondered how long it would take (centuries) to figure out where I was wrong . It was exactly Casing issue! Very thanks!

milosmijakovac avatar Dec 13 '17 21:12 milosmijakovac

@rgantla OMG!!. That was exactly the problem. It was a Casing Issue. Thanks!!

estebanluengo avatar Dec 14 '17 08:12 estebanluengo

In my case it was not exactly a casing issue but also an import that had to be fixed.

Using ngx-clipboard I had to change the import from import { ClipboardModule } from 'ngx-clipboard/index'; to import { ClipboardModule } from 'ngx-clipboard/dist';.

Hope that helps someone in the same situation.

sbley avatar Dec 14 '17 09:12 sbley

I have exactly the same problem if I run ng serve from symbolically linked folder (~/src/... in my case). However, if I run ng serve from the real folder (/c/src/... in my case), everything is fine.

zhekaus avatar Dec 18 '17 19:12 zhekaus

This issue caused most of the teams in my Enterprise company to drop all their Angular X projects & switch to React based application (because we have a huge shared code-base & there is no easy way to export Angular projects as NPM libraries).

I actually liked Angular that's too bad :\ hope this will be solved soon enough before the point of no return.

bnohad avatar Dec 20 '17 16:12 bnohad

I had the same problem in one of my npm modules. I've solved it by adding a declaration files *.d.ts. I think you should open an issue to the npm module that your using.

ranbuch avatar Jan 05 '18 20:01 ranbuch

I left a comment https://github.com/angular/angular-cli/issues/6195#issuecomment-355992061 that might help some people resolve issues around this.

txinfo avatar Jan 08 '18 15:01 txinfo

@SaltyDH I had a similar issue but found that it was a result of the version of TypeScript that I had installed. I had ^2.5.1 in my package.json and thought I was using 2.5.3. Turns out I had 2.5.1 installed and it was causing the issue.

  1. I changed my dependency to 2.5.x, the same as the Angular repo
  2. Did an npm install
  3. Verified with npm list typescript that I had 2.5.3 installed
  4. Ran ng serve and my app built without issue

sternetj avatar Jan 08 '18 18:01 sternetj

@rkrisztian I had the issue just with ng test. Add ../ in the include paths in the tsconfig.spec.json resolve my problem. It seems the inheritance of the tsconfig.json doesn't work for the paths, because the base directory isn't the same.

tobat50 avatar Jan 11 '18 10:01 tobat50

I have an issue with the workaround. My SO question: https://stackoverflow.com/questions/48449948/how-to-import-repo-with-uncompiled-typescript-in-angular-5-x

BBaysinger avatar Jan 25 '18 19:01 BBaysinger

Also, if working with ASP.Core 2.0 template, the src folder is renamed to ClientApp so in that case you should add it to your tsconfig.json file:

{
  "compilerOptions": {
    // stuff
  },
  "include": [
    "./ClientApp/**/*.ts"
  ]
}

AndreiLucaci avatar Jan 29 '18 10:01 AndreiLucaci

I have a large enterprise app with the "code sharing" setup mentioned above. Essentially there are lazy routes defined that load feature modules, these modules are shells that in turn import from node_modules where the actual feature modules (in module.ts files via index.ts barrels) are pulled in from our internal npme/nexus. Worked like a champ with Ng4 and enabled our distributed development across multiple teams/repos.

With Ng5, after updating the tsconfig files, it will work in JiT (ng serve and ng build).

AoT will build, but when the app is started a "Uncaught TypeError: ctor is not a constructor" is thrown immediately .

b-johnse avatar Jan 30 '18 21:01 b-johnse

Seems silly that we have to include files that are normally part of the build. Currently my whatever is complaining that " \src\main.ts is missing from the TypeScript compilation." but that's the very very first file angular looks at, so that seems strange.

Oh well.

stofte avatar Jan 31 '18 13:01 stofte

@filipesilva

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.

What exactly do you mean? We use ng-packagr, which ships *.d.ts files and we thought that is the right way to deliver a package.

plamf avatar Feb 02 '18 09:02 plamf

@plamf Shipping *.d.ts is fine, it is shipping the original source *.ts files that is not.

benelliott avatar Feb 02 '18 10:02 benelliott

Well we’re not ‘shipping’ anything. This is an internal library for which we have control over which compliler we use. So packaging for distribution is a unnecessary step. We did figure out how to import it with straight .ts files, as the SO question was answered satisfactorily.

BBaysinger avatar Feb 04 '18 01:02 BBaysinger

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

ORESoftware avatar Feb 15 '18 00:02 ORESoftware

@filipesilva. I am facing the same issue Just to summarize, we have a large project. So 1 project is used as library and sits in the node_modules folder. When on Angular 4 it works fine but when upgraded it is throwing me this error: Module build failed: XXX file is missing in Typescript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. I have read this whole ticket and specially implemented what you suggested of manually adding it in tsconfig.json. But when I do that it prompts me a different error: Unknown compiler option 'include' and 'exclude'. It would be great help if you could get me out of this issue. Thank you in advance. Just to reiterate I have read through the whole blog and tried different solutions it does not seem to work. Again Thank you in advance.

kaushikdighe avatar Feb 16 '18 23:02 kaushikdighe

@andi-wr Thank you for the solution but it still does not work. It gives me whole lot of errors. Saying cannot find name 'describe'; cannot find name 'beforeEach' etc in all the files. This is a huge list of errors.

kaushikdighe avatar Feb 20 '18 15:02 kaushikdighe

@filipesilva I am getting the below error and the third party literary do not have .ts file. can you help

ERROR in ./node_modules/agm-direction/src/agm-direction.module.ts Module build failed: Error: D:\TandT\TandTSrc\node_modules\agm-direction\src\agm-direction.module.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format (https://goo.gl/jB3GVv). at AngularCompilerPlugin.getCompiledFile (D:\TandT\TandTSrc\node_modules@ngtools\webpack\src\angular_compiler_plugin.js:656:23) at plugin.done.then (D:\TandT\TandTSrc\node_modules@ngtools\webpack\src\loader.js:467:39) at at process._tickCallback (internal/process/next_tick.js:169:7) @ ./node_modules/agm-direction/index.js 6:9-46 @ ./src/app/app.module.ts @ ./src/main.ts @ multi ./src/main.ts

princeprathap avatar Mar 01 '18 04:03 princeprathap