angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.77k stars 11.98k forks source link

[Angular9] - module is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property #17804

Closed Gnorro closed 4 years ago

Gnorro commented 4 years ago

🐞 bug report

Description

We have lot of errors when enabling Ivy and making a ng serve

πŸ”₯ Exception or Error


ERROR in ./src/app/features/homepage/homepage-under-fold/homepage-under-fold.module.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: D:\dev\ecommerce\frontend\branches\2020-01-15_update-to-angular-9\src\app\features\homepage\homepage-under-fold\homepage-under-fold.module.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (D:\dev\ecommerce\frontend\branches\2020-01-15_update-to-angular-9\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:900:23)
    at plugin.done.then (D:\dev\ecommerce\frontend\branches\2020-01-15_update-to-angular-9\node_modules\@ngtools\webpack\src\loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ./src/app/features/layout-root/footer/footer.module.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):

Same error on lots of modules

Error screenshot: Cattura2

Second error is about ngx-gallery lib I suppose:


ERROR in node_modules/ngx-gallery/ngx-gallery-helper.service.d.ts:1:22 - error TS2724: Module '"D:/dev/ecommerce/frontend/branches/2020-01-15_update-to-angular-9/node_modules/@angular/core/core"' has no exported member 'Renderer'. Did you mean 'Renderer2'?

1 import { ElementRef, Renderer } from '@angular/core';
                       ~~~~~~~~

  node_modules/@angular/core/core.d.ts:5612:31
    5612 export declare abstract class Renderer2 {
                                       ~~~~~~~~~
    'Renderer2' is declared here.
node_modules/ngx-gallery/ngx-gallery-preview.component.d.ts:1:89 - error TS2724: Module '"D:/dev/ecommerce/frontend/branches/2020-01-15_update-to-angular-9/node_modules/@angular/core/core"' has no exported member 'Renderer'. Did you mean 'Renderer2'?

1 import { ChangeDetectorRef, EventEmitter, OnInit, OnChanges, SimpleChanges, ElementRef, Renderer } from '@angular/core';
                                                                                          ~~~~~~~~

  node_modules/@angular/core/core.d.ts:5612:31
    5612 export declare abstract class Renderer2 {
                                       ~~~~~~~~~
    'Renderer2' is declared here.

Error screenshot: Cattura

This lib is already updated to last version

🌍 Your Environment

Angular Version:


Angular CLI: 9.0.0-rc.8
Node: 10.16.3
OS: win32 x64

Angular: 9.0.0-rc.8
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router, service-worker
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.0-rc.8
@angular-devkit/build-angular     0.900.0-rc.8
@angular-devkit/build-optimizer   0.900.0-rc.8
@angular-devkit/build-webpack     0.900.0-rc.8
@angular-devkit/core              9.0.0-rc.8
@angular-devkit/schematics        9.0.0-rc.8
@angular/cdk                      9.0.0-rc.7
@angular/http                     7.2.15
@angular/material                 9.0.0-rc.7
@ngtools/webpack                  9.0.0-rc.8
@schematics/angular               9.0.0-rc.8
@schematics/update                0.900.0-rc.8
rxjs                              6.5.4
typescript                        3.6.4
webpack                           4.41.2

Anything else relevant?

Our package.json:


{
  "name": "xxx",
  "version": "0.0.0",
  "scripts": {
    "ng": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng",
    "start": "npm run ng -- serve",
    "build": "npm run ng -- build",
    "test": "npm run ng -- test",
    "lint": "npm run ng -- lint",
    "e2e": "npm run ng -- e2e",
    "analyze": "webpack-bundle-analyzer dist/stats.json",
    "compodoc": "npx compodoc -p src/tsconfig.app.json",
    "build:stats": "ng build --stats-json"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "1.0.0-beta.7",
    "@agm/js-marker-clusterer": "1.0.0-beta.3",
    "@angular/animations": "9.0.0-rc.8",
    "@angular/cdk": "9.0.0-rc.7",
    "@angular/common": "9.0.0-rc.8",
    "@angular/compiler": "9.0.0-rc.8",
    "@angular/core": "9.0.0-rc.8",
    "@angular/forms": "9.0.0-rc.8",
    "@angular/http": "7.2.15",
    "@angular/material": "9.0.0-rc.7",
    "@angular/platform-browser": "9.0.0-rc.8",
    "@angular/platform-browser-dynamic": "9.0.0-rc.8",
    "@angular/platform-server": "9.0.0-rc.8",
    "@angular/router": "9.0.0-rc.8",
    "@angular/service-worker": "9.0.0-rc.8",
    "@satispay/web-button-factory": "1.4.3",
    "angular4-social-login": "1.1.1",
    "braintree-web": "3.52.1",
    "braintree-web-drop-in": "1.20.1",
    "classlist.js": "1.1.20150312",
    "codice-fiscale-js": "2.1.0",
    "core-js": "^3.6.4",
    "domino": "2.1.3",
    "express": "4.17.1",
    "font-awesome": "4.7.0",
    "hammerjs": "2.0.8",
    "js-marker-clusterer": "1.0.0",
    "lory.js": "^2.5.3",
    "md5": "2.2.1",
    "moment-mini-ts": "2.20.1",
    "ng-lazyload-image": "5.1.2",
    "ng2-cookies": "1.0.12",
    "ngx-gallery": "^5.10.0",
    "ngx-json-ld": "0.3.1",
    "ngx-loadable": "^2.1.1",
    "ngx-responsive": "6.0.0",
    "ngx-swiper-wrapper": "4.9.0",
    "paypal-checkout": "4.0.285",
    "rxjs": "6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.900.0-rc.8",
    "@angular/cli": "9.0.0-rc.8",
    "@angular/compiler-cli": "9.0.0-rc.8",
    "@angular/language-service": "9.0.0-rc.8",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "0.2.2",
    "node-ts": "5.0.1",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "3.6.4",
    "webpack-bundle-analyzer": "3.3.2"
  }
}

Our tsconfig.json:


{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "src",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "esnext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

Our tsconfig.app.json:


{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "types": []
  },
  "angularCompilerOptions": {
    "enableIvy": true
  },
  "files": [
    "main.ts",
    "polyfills.ts"
  ],
  "include": [
    "../node_modules/@satispay/web-button-factory/src/*",
    "./**/*.d.ts"
  ]
}

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "xxx": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {
        "@schematics/angular:component": {
          "styleext": "scss"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "aot": true,
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "stylePreprocessorOptions": {
                            "includePaths": ["src/assets/sass"]
            },
            "lazyModules": [
              "src/app/features/layout-root/footer/footer.module",
              "src/app/features/layout-root/layout-root-under-fold/layout-root-under-fold.module",
              "src/app/features/homepage/homepage-under-fold/homepage-under-fold.module",
              "src/app/header/menu/item-menu/menu-sections/appliances-menu-section/appliances-menu-section.module",
              "src/app/header/menu/item-menu/menu-sections/casa-menu-section/casa-menu-section.module",
              "src/app/header/menu/item-menu/menu-sections/brico-menu-section/brico-menu-section.module",
              "src/app/header/menu/item-menu/menu-sections/engines-menu-section/engines-menu-section.module",
              "src/app/header/menu/item-menu/menu-sections/info-menu-section/info-menu-section.module",
              "src/app/header/menu/item-menu/menu-sections/other-menu-section/other-menu-section.module",
              "src/app/header/menu/item-menu/menu-sections/phone-menu-section/phone-menu-section.module",
              "src/app/header/menu/item-menu/menu-sections/toys-menu-section/toys-menu-section.module",
              "src/app/header/menu/item-menu/menu-sections/tv-audio-video-menu-section/tv-audio-video-menu-section.module",
              "src/app/header/menu/item-menu/menu-sections/video-games-menu-section/video-games-menu-section.module",
              "src/app/header/menu/item-menu/menu-sections/club-menu-section/club-menu-section.module"
            ],
            "assets": [
              "src/assets",
              "src/favicon.ico",
              "src/maintenance.html",
              "src/assets/js/ads.js",
              "src/manifest.json"
            ],
            "styles": [
              "src/styles/styles.scss",
              "src/styles/xxx.scss",
              "node_modules/font-awesome/css/font-awesome.css"
            ],
            "scripts": [],
            "es5BrowserSupport": true
          },
          "configurations": {
            "staging": {
              "budgets": [
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "ngswConfigPath": "src/app/config/ngsw-config.json",
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.staging.ts"
                },
                {
                  "replace": "src/index.html",
                  "with": "src/index.staging.html"
                }
              ],
              "serviceWorker": true
            },
            "preprod": {
              "budgets": [
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "ngswConfigPath": "src/app/config/ngsw-config.json",
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.preprod.ts"
                },
                {
                  "replace": "src/index.html",
                  "with": "src/index.preprod.html"
                }
              ],
              "serviceWorker": true
            },
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                },
                {
                  "replace": "src/index.html",
                  "with": "src/index.production.html"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "ngswConfigPath": "src/app/config/ngsw-config.json",
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb"
                }
              ],
              "serviceWorker": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "xxx:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "xxx:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "xxx:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.scss"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "server": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            "outputPath": "dist",
            "main": "src/main.server.ts",
            "tsConfig": "src/tsconfig.server.json"
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            ,              "optimization": true
}
          }
        }
      }
    },
    "xxx-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "prefix": "",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "xxx:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "xxx:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "xxx" 
}

Thanks for your help

Gnorro commented 4 years ago

Without Ivy we get different erros. I will open a new 3ad for that.

Some other info about our project, because I think that this problem on lazy route could be related to this (but I'm not sure about that): In our core.module we have this:


import { lazyloadFilemappings } from 'app/config/lazyload-filemappings';

@NgModule({
  imports: [
    ...
    LoadableModule.forRoot({
      fileMappings: lazyloadFilemappings
    })
  ],
 

This file is:


 export const lazyloadFilemappings = {
  'footer': 'src/app/features/layout-root/footer/footer.module#FooterModule',
  'layout-root-under-fold':
    'src/app/features/layout-root/layout-root-under-fold/layout-root-under-fold.module#LayoutRootUnderFoldModule',
  'homepage-under-fold':
    'src/app/features/homepage/homepage-under-fold/homepage-under-fold.module#HomepageUnderFoldModule',
  'appliances-menu-section':
    'src/app/header/menu/item-menu/menu-sections/appliances-menu-section/appliances-menu-section.module#AppliancesMenuSectionModule',
  'casa-menu-section':
    'src/app/header/menu/item-menu/menu-sections/casa-menu-section/casa-menu-section.module#CasaMenuSectionModule',
  'brico-menu-section':
    'src/app/header/menu/item-menu/menu-sections/brico-menu-section/brico-menu-section.module#BricoMenuSectionModule',
  'engines-menu-section':
    'src/app/header/menu/item-menu/menu-sections/engines-menu-section/engines-menu-section.module#EnginesMenuSectionModule',
  'info-menu-section':
    'src/app/header/menu/item-menu/menu-sections/info-menu-section/info-menu-section.module#InfoMenuSectionModule',
  'other-menu-section':
    'src/app/header/menu/item-menu/menu-sections/other-menu-section/other-menu-section.module#OtherMenuSectionModule',
  'phone-menu-section':
    'src/app/header/menu/item-menu/menu-sections/phone-menu-section/phone-menu-section.module#PhoneMenuSectionModule',
  'toys-menu-section':
    'src/app/header/menu/item-menu/menu-sections/toys-menu-section/toys-menu-section.module#ToysMenuSectionModule',
  'tv-audio-video-menu-section':
    'src/app/header/menu/item-menu/menu-sections/tv-audio-video-menu-section/tv-audio-video-menu-section.module#TvAudioVideoMenuSectionModule',
  'video-games-menu-section':
    'src/app/header/menu/item-menu/menu-sections/video-games-menu-section/video-games-menu-section.module#VideoGamesMenuSectionModule',
  'club-menu-section':
    'src/app/header/menu/item-menu/menu-sections/club-menu-section/club-menu-section.module#ClubMenuSectionModule'
};

In our main menu component we have:

<div class="item-menu" (mouseover)="openMenu()" (mouseleave)="this.menuState = false">
  <a (click)="goToPath('xxx')">{{ this.mainitem }}</a>
  <div class="submenu-container" [ngClass]="{ open: this.menuState == true }">
    <ngx-loadable [show]="true" [module]="'tv-audio-video-menu-section'"></ngx-loadable>
  </div>
</div>

We load that using ngx-loadable

Beginning from angular 8 syntax for lazy load changed from: { path: 'cashback', loadChildren: './features/cashback/cashback.module#CashbackModule' } to { path: 'cashback', loadChildren: () => import('./features/cashback/cashback.module').then(m => m.CashbackModule) }

I don't know if I need to change something also in lazyloadFilemappings values, for example remove everything after "#", so something like this: from: 'tv-audio-video-menu-section': 'src/app/header/menu/item-menu/menu-sections/tv-audio-video-menu-section/tv-audio-video-menu-section.module#TvAudioVideoMenuSectionModule' to 'tv-audio-video-menu-section': 'src/app/header/menu/item-menu/menu-sections/tv-audio-video-menu-section/tv-audio-video-menu-section.module'

Errors I get are related to those modules defined in lazyloadFilemappings. This is the reason why I wanted to give more info about that.

Thanks

Splaktar commented 4 years ago

Did you use ng update for the update? It should update your tsconfig.json to avoid this.

Have you taken a look at update.angular.io?

Gnorro commented 4 years ago

I followed instruction on update.angular.io

Yes, I ran ng update

gkalpak commented 4 years ago

Regarding the Renderer/Renderer2 error: Renderer has been deprecated since v4 and is removed in v9 (see https://v9.angular.io/guide/deprecations#removed-apis). You can open an issue on the 3rd-party library to upgrade to Renderer2 (you can point them here for details: https://next.angular.io/guide/migration-renderer).

Apart from that, I am not sure what the problem is. Could you create a minimal reproduction? (FWIW, I don't think this is related to ngcc.)

wmarques commented 4 years ago

I have the same issue but I'm on a project with some AngularJS files written in TypeScript. I updated my tsconfig.app.json to add

"files": ["src/app/main.ts", "html.d.ts", "src/app/constants.ts"],
  "include": ["src/**/*.d.ts"],

But I have this kind of error when I launch my app.

For information: cookie.service.ts is an angularJS service

I have other errors, all of them are about AngularJS TypeScript files.

ERROR in ./src/app/utils/cookie/cookie.service.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Users/wmarques/workspace/artel/telematics-services/telematics-bo-web/src/app/utils/cookie/cookie.service.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Users/wmarques/workspace/artel/telematics-services/telematics-bo-web/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:909:23)
    at /Users/wmarques/workspace/artel/telematics-services/telematics-bo-web/node_modules/@ngtools/webpack/src/loader.js:41:31
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
 @ ./src/app/utils/utils.module.js 3:0-56 12:96-109
 @ ./src/app/app.module.ts
 @ ./src/app/app.ng2.module.ts
 @ ./src/app/main.ts

The fix is probably to add those files to the files array but I don't think that's a very clean solution...

andreElrico commented 4 years ago

So I went into tsconfig.app.json and tsconfig.spec.json and added

  "include": [
   ...
    "**/app/lazyModules/**/*.ts"
  ]

by using **/ in the front I prevent that path bullshit guessing because I NEVER know what they want from me here /scr , scr, ./ .. etc.

[from angular update page]

We have updated the tsconfig.app.json to limit the files compiled. If you rely on other files being included in the compilation, such as a typings.d.ts file, you need to manually add it to the compilation.

I believe this is exactly what they mean. We have to include those modules, manually.

Hope this helps someone.

SchnWalter commented 4 years ago

This sounds more like a support request for StackOverflow than a bug report.

You are using ngx-gallery as a dependency and it imports Renderer, but there has been no such export in @angular/core for a long time. You should check if ngx-gallery has an update. Also, for a successful update, you should always follow the official docs - with emphasis on https://update.angular.io/

A quick tip: whenever I update a project, I always compare the project files with the files from a newly generated Angular project and I port all the changes so that the project looks as much as possible as a brand new project.

alan-agius4 commented 4 years ago

Hi all,

There seems to have been multiple issues reported here.

1) ngx-gallery If you are using ngx-gallery, please see the comment from @SchnWalter here: https://github.com/angular/angular-cli/issues/17804#issuecomment-634867805

2) lazy loading without using dynamic imports If you are using lazy loading, either via the deprecated string based syntax, or some other custom way, which is not statically analysable by the build system. You will need to need to include the lazy loaded modules manually inside the compilation, by specifying either include or files options in the TypeScript configuration file.

Example

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {...},
  "files": [...],
  "include": [
    "src/**/*.d.ts",
    "src/**/*.lazy.ts",  
  ]
}

More info about lazy loading: https://angular.io/guide/lazy-loading-ngmodules

A quick tip: whenever I update a project, I always compare the project files with the files from a newly generated Angular project and I port all the changes so that the project looks as much as possible as a brand new project.

When using ng update we actually executer migrations to update existing projects to have the same structure as new projects.

angular-automatic-lock-bot[bot] commented 4 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.