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

@filipesilva I see hundreds of errors so its hard to sort through them. From what I can see at the moment it's all of "my" library packages, packages that we build and publish to a local repository. We package all of the .ts files as well as a webpacked bundle file.

When we were building with SystemJS it made sense that we had to explicitly specify all of the bundles to include from node_modules, but with the CLI it seemed to just work without any extra specifications. It made our lives a thousand times easier. But now it seems what we thought was a feature was actually a bug in CLI and possibly something that we are doing wrong (and have been for more than a year now).

So what exactly is the problem? Is it that the CLI was compiling the .ts files that we had in our library packages and so did not need the bundles? If that is the case then how do we now tell the CLI to use the bundle? Is it something to do differently when packaging the library bundles or is it some angular-cli.json configuration we have to change.

Sorry, up until now we had though we had finally figured out this JavaScript eco system, but now it seems we still have some things to learn.

KevinFernandes avatar Nov 03 '17 11:11 KevinFernandes

@KevinFernandes ok so that it happens on your local libs makes sense considering the other reports in this issue. Yes, before it seems like the CLI was compiling the TS in your local libraries, which was just a ticking time bomb really.

The way to address this in your codebase really depends on how you build your libs... Do you use an existing library to do it? I think a lot of users use https://github.com/dherges/ng-packagr and seem to be happy with it. I haven't myself though.

filipesilva avatar Nov 03 '17 12:11 filipesilva

I can report a similar issue:

I have a standard, cli generated, folder structure ( Windows platform ) I simply share some modules between different applications at the source level.

Under src there are the following folders:

  • app
  • packages ( simlink )

Under packages:

  • combo-components
  • ....

Each folder is a module ( proper module.ts ) and has an index.ts for the exports.

tsconfig.json looks like this:

"compilerOptions": {
    "baseUrl": "src",
    "paths": {
      "@combo-components/core": [
        "packages/combo-components/src"
      ],
      "@catol/core": [
        "packages/catol-core/src"
      ]
    }

An import statement looks like this: import { DataSourceResult, NotificationService } from '@combo-components/core';

It worked fine till angular 4.x and cli 1.4.x After upgrading to 5.0 & cli 1.5.0, ng build fails with the following error:

ERROR in ../catol/combo-components/src/index.ts Module build failed: Error: C:\Users...\workspace\catol\combo-components\src\index.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:\Users...\workspace\playground\node_modules@ngtools\webpack\src\angular_compiler_plugin.js:624:23) at plugin.done.then (C:\Users...\workspace\playground\node_modules@ngtools\webpack\src\loader.js:467:39) @ ./src/app/app.module.ts 13:0-63 @ ./src/main.ts @ multi ./src/main.ts

Casing checked, also added the include property suggested by @filipesilva

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

The error changes slightly:

ERROR in ./src/main.ts Module build failed: Error: C:\Users...\workspace\playground\src\main.ts is not part of the compilation output. Please check the other error messages for details. at AngularCompilerPlugin.getCompiledFile (C:\Users...\workspace\playground\node_modules@ngtools\webpack\src\angular_compiler_plugin.js:629:23) at plugin.done.then (C:\Users...\workspace\playground\node_modules@ngtools\webpack\src\loader.js:467:39) at process._tickCallback (internal/process/next_tick.js:109:7) @ multi ./src/main.ts ERROR in ./src/polyfills.ts ...

Adding main&polyfill to the include path doesn't help either.

emazv72 avatar Nov 06 '17 14:11 emazv72

The same issue with fresh-created app using ng new Angular CLI: 1.5.0 Node: 6.10.3 OS: win32 x64 Angular: 5.0.0

zhekaus avatar Nov 06 '17 16:11 zhekaus

I was having this issue and it was a case issue.

I was trying to do this:

import { IJobModel, JobModel } from "./jobModels/job.model";

which should be

import { IJobModel, JobModel } from "./JobModels/job.model";

(./jobModels was camel cased instead of upper case)

scottieslg avatar Nov 06 '17 22:11 scottieslg

have you tried with --preserve-symlinks flag? https://github.com/angular/angular/issues/20091

sandangel avatar Nov 07 '17 00:11 sandangel

@sandangel Thank you that worked for me, no need to add the 'include' property in tsconfig.json

After upgrade, either run

ng serve --preserve-symlinks

or update .angular-cli.json

...
 "defaults": {
    "styleExt": "css",
    "component": {},
    "build": {
      "preserveSymlinks": true
    }

if you have symlinks in the source tree.

emazv72 avatar Nov 07 '17 09:11 emazv72

I'm using a 3rd party library from Google called api-ai-javascript which is installed in the node_modules folder, using ng serve --preserve-symlinks does not work and neither does updating my angular-cli.json file, I have to explicitly update my tsconfig file with include in order to overcome the following error

Module build failed: Error: C:\Users\Development\Documents\Projects\proj\node_modules\api-ai-javascript\index.ts is not part of the compilation output. Please check the other error messages for details. 
at AngularCompilerPlugin.getCompiledFile (C:\Users\Development\Documents\Projects\proj\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:629:23)
   at plugin.done.then (C:\Users\Development\Documents\Projects\proj\node_modules\@ngtools\webpack\src\loader.js:467:39)
   at <anonymous>
   at process._tickCallback (internal/process/next_tick.js:188:7)
@ ./src/app/services/bot/bot.service.ts 12:0-48
@ ./src/app/components/common/app-common.module.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi ./src/main.ts

Only after updating to Angular 5.0.0 and Angular-cli 1.5.0 did the issue start occurring.

ag-susini avatar Nov 07 '17 11:11 ag-susini

I'm also seeing the issue after upgrading to Angular 5 and cli 1.5.0 with a third-party logger module that had no issues previously.

Tried suggested methods posted here still the same error.

ERROR in ./node_modules/angular2-logger/app/core/level.ts Module build failed: Error: node_modules/angular2-logger/app/core/level.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.

SamD avatar Nov 07 '17 21:11 SamD

I am have the same error, although mine came about after I imported the 'Input' class from '@angular/core'.

import {Component, OnInit, ViewEncapsulation, Input} from '@angular/core';

After I used the @Input() on the variable hero: Hero it breaks. If I don't type hero like @Input() hero it is fine, but as soon as I add : Hero; it breaks.

MrVintage710 avatar Nov 08 '17 02:11 MrVintage710

@scottieslg pointed me in the right direction. (Typo in path casing). Additionally I had several backticks (`) in my compoments that were compiling before. single quotes (') resolved the issue.

michaelwaihenya avatar Nov 08 '17 20:11 michaelwaihenya

I encountered the problem with a project having a Symfony like architecture.

Meaning there is : ./tsconfig.json ./src/tsconfig.app.json ./src/SomeFolder/app/*.ts...

There are dependencies between each bundles.

One of the dependencies was thrown in "...is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property"

I solved the problem by including every ts files as suggested by @filipesilva but in a different order.

=> Bundle B needed by Bundle A & C so tsconfig.app.json like : { "include": [ "pathToBundleB/**/*.ts", "pathToBundleA/**/*.ts", "pathToBundleC/**/*.ts", ] } instead of : { "include": [ "pathToBundleA/**/*.ts", "pathToBundleB/**/*.ts", "pathToBundleC/**/*.ts", ] }

That's kinda weird. Looks like @ngtools/webpack/src/angular_compiler_plugin.js:624:23), the function this._compilerHost.fileExists is looking for bundles loaded before, and not after..

little-boy avatar Nov 09 '17 15:11 little-boy

I'm getting this error for files that are referenced in our app.module.ts. Its almost like this file is treated differently in some way because its the module referenced in the AngularCompilerPlugin options??? I've tried manually adding the module to the tsconfig files section but that hasn't resolved it.

matt-psaltis avatar Nov 10 '17 01:11 matt-psaltis

We are having the same issue. We have a private repo where we have published a library that we use. We have this lib as a dependency in our client, when compiling in Angular 5 we get the following error but ONLY in JIT mode, if we use a ng serve --aot or ng build --aot or --prod it works fine. Not sure what is the issue here. We are using Angular 5.0.1 with CLI 1.5.0

We tried using includes in tsconfig, while that solves this issue it generates another different error that my json module declarations are not found which is specified in typings.d.ts (with a declare module "*.json").

ERROR in ./node_modules/@myscope/services-lib/index.ts
Module build failed: Error: 
[path]\node_modules\@myscope\services-lib\index.ts is not part of the compilation output. 
Please check the other error messages for details.
    at AngularCompilerPlugin.getCompiledFile ([path]\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:629:23)

sbkpilot1 avatar Nov 10 '17 22:11 sbkpilot1

I've managed to resolve the issue I was having by, as per @filipesilva's advice, compiling the TS code from my library and configuring it so my downstream projects could consume it. I did have a lot of trouble with this though, so I want to share some details in the hope they'll help others with the same frustrations.

Most of the documentation and discussion available frames these repos we're installing via npm as "libraries" in the open source sense of the term: The code is on github, the artifacts are published to npm, and they must be built for general consumption (ie. accounting for different projects with different ES targets). My situation (which is not unique, from the sound of things) is different in that my "library" is for internal company use only. To help separate this use case from the "open source library" scenario, I'm going to call what I've got a "shared codebase".

Your starting point should be @filipesilva's angular-quickstart-lib repo. If, like me, you've got a "shared codebase" then you don't need everything from here. The key things you need are:

  1. To inline resources before you compile them (ie. templateUrl becomes template)
  2. To compile the TS code using ngc, with appropriate tsconfig.json settings
  3. To add module and typings properties to your package.json, pointing at the index.js and index.d.ts of your compiled code.

What you don't need is bundling (Just use the raw *.js files), and you probably only need a single compile target (ES5 or ES2015). So you can strip down a lot of the build.js file (removing the need for a fair few extra npm dependencies) and ignore references to flatModule in the tsconfig.lib.json.

I hope that helps.

rolaveric avatar Nov 10 '17 23:11 rolaveric

This really stressful!

Myself and my team, we have put all energy believing and trusting Angular, that's this time things will be different not like from angularJs to angular 2.

And we could jump a long time from angularJs to ReactJs or Aurelia or maybe VueJs, but the love and trust we had it keeps as loving Angular and believing that we won't have same stress like we had from angularJs to angular 2.

Now we already with big projects out there, using third-party open source libraries, which till angular 4.3, everything was fine.

But now in angular 5 with the CLI 1.5, we were expecting the upgrade to be smooth and not having this kind of issue. So now we're stuck and hoping that the creators of the libraries they update the package.

And the questions come again, should we keep believing that angular will have the success like angularJs had on the past, or now is time to move on trying something different because this is a nightmare, and each version got different stories, and we must signup new courses to learn over.

I'm sorry for my comments, but this how it feels like.

image

jacinto-joao avatar Nov 11 '17 11:11 jacinto-joao

@jjoao07 Sorry you are having trouble. The issue isn't an angular issue it is a typescript issue. To solve it for linked libraries that have typescript shipped in them you can add that to your tsconfig "includes" property. So if you have a folder in your node modules called "my-lib" you can add. The typescript compiler by default does not see the typescript code in node_modules by default (and it shouldn't). I hope this helps.

this is the same as mentioned by @filipesilva and @little-boy

{
    "includes": ["node_modules/my-lib"]
}

deebloo avatar Nov 11 '17 15:11 deebloo

@deebloo if the Typescript compiler shouldn't be looking at ts code in the node modules then perhaps adding an includes is not the best solution for this? Should we be packaging our libraries differently?

sbkpilot1 avatar Nov 11 '17 18:11 sbkpilot1

@sbkpilot1 overall yes. if you are publishing a module you should only be distributing javascript and the generated type definitions. The solution I mentioned is only a workaround

deebloo avatar Nov 12 '17 04:11 deebloo

Adding the following to .npmignore (in addition to 'includ'ing in tsconfig.json, of course) fixes it for me.

# Ignored files
*.ts
!*.d.ts

akkumar avatar Nov 13 '17 10:11 akkumar