首页 > 解决方案 > TypeScript 编译中缺少 Angular- 模块。请通过 'files' 或 'include' 属性确保它在您的 tsconfig 中

问题描述

ng serve 后出现此错误: ./src/app/Modeles/utilisateurs.model.ts 中的错误模块构建失败(来自 ./node_modules/@ngtools/webpack/src/index.js):错误:C:\Users TypeScript 编译中缺少 \xx\src\app\Modeles\utilisateurs.model.ts。请通过 'files' 或 'include' 属性确保它在您的 tsconfig 中。

tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "lib": [
      "es2018",
      "dom"
    ],
    "types": ["gapi", "gapi.auth2"],

  },

  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  },

  "include": [
    "./src", 
    "node_modules/@jaspero/ng2-select",
    "**/app/lazyModules/**/*.ts"
  ]
}

tsconfig.app.json:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": ["gapi", "gapi.auth2"],
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}

角.json:

"projects": {
    "xx": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/xx",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "preserveSymlinks": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "src/styles.scss"
            ],
            "scripts": []
          },

标签: angulartypescripttsconfig

解决方案


在 tsconfig.app.json 更改您的包含数组

"include": [
    "src/**/*.d.ts"
  ]

"include": [
    "src/**/*.d.ts",
    "src/**/*.ts"
  ]

推荐阅读