第一次使用firestore,我得到这个错误。根据我的研究,这似乎是艾薇的问题。我没有太多修改tsconfig.app的经验。json,这是我所指向的方向,然后是其他答案。

我唯一能从最初的项目中修改的是使用Angular Fire 6而不是5,我最初是按照教程做的。

package.json:

{
  "name": "language",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~9.0.1",
    "@angular/cdk": "^9.0.0",
    "@angular/common": "~9.0.1",
    "@angular/compiler": "~9.0.1",
    "@angular/core": "~9.0.1",
    "@angular/fire": "^6.0.0-rc.1",
    "@angular/flex-layout": "^9.0.0-beta.29",
    "@angular/forms": "~9.0.1",
    "@angular/material": "^9.0.0",
    "@angular/platform-browser": "~9.0.1",
    "@angular/platform-browser-dynamic": "~9.0.1",
    "@angular/router": "~9.0.1",
    "firebase": "^7.8.2",
    "rxjs": "~6.5.4",
    "rxjs-compat": "^6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.900.2",
    "@angular/cli": "~9.0.2",
    "@angular/compiler-cli": "~9.0.1",
    "@angular/language-service": "~9.0.1",
    "@types/node": "^12.11.1",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.7.5",
    "@angular-devkit/architect": "^0.900.0-0 || ^0.900.0",
    "firebase-tools": "^7.12.1",
    "fuzzy": "^0.1.3",
    "inquirer": "^6.2.2",
    "inquirer-autocomplete-prompt": "^1.0.1"
  }
}

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "language": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/language",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css",
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "language:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "language:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "language:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css",
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "language:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "language:serve:production"
            }
          }
        },
        "deploy": {
          "builder": "@angular/fire:deploy",
          "options": {}
        }
      }
    }
  },
  "defaultProject": "language"
}

tsconfig.app.json

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

谢谢!


根据文档,修正了选择退出常春藤的问题。

https://angular.io/guide/ivy

更改tsconfig.app.json以选择退出Ivy。

"enableIvy": false

你的模块还没有被Angular服务器在node ng serve中加载,所以重启你的服务器,让服务器加载你刚刚在@NgModule app.module.ts中添加的模块


这对我来说很管用:

1)停止ng服务器

2)重新安装软件包

npm install your-package-name

3)重新运行

ng serve

NPM缓存清理:force ->清理缓存可能会解决这个问题。


我已经测试了这里所有的答案,但没有一个对我有用。所以我决定改变angular.js文件。这里有一个aot选项是真的。然后我把它改成假的,错误就消失了!

"options": {
            "outputPath": "dist/DateMeUI",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": false, // here you have to change
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          },

但是,我得到了'tsconfig。app。json',我在我的项目中找不到(也许你必须手动添加这个),通过这个文件,你可以设置“enableIvy”:false,因为其他人提到了它。tsconfig.app.json


这个问题将通过在package.json中添加下面的postinstall脚本来解决。

它将在npm安装后运行。

"scripts": {
   "postinstall": "ngcc"
}

添加以上代码后,运行npm install

当我升级到Angular 9+时,这是可行的


此错误显示当您在imports中添加组件声明:[]而不是声明:[]时,例如:

declarations: [
  AppComponent,
],
imports: [
  BrowserModule,
  AppRoutingModule,
  SomeComponent <-----------wrong
],

当我在app.module.ts中导入MatSnackBar而不是MatSnackBarModule时,我得到了这个错误。


为我工作

angular.json

"aot": false

这对我很有用

停止ng服务器(ctrl+c) 再次运行 NPM start / ng serve——打开


只需转到项目中的tsconfig.app.json,并从中删除所有内容

并复制下面的代码并粘贴它。它会解决你的问题:)

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": [],
  },

  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ],
  "angularCompilerOptions": {
    "enableIvy": false
  }
}

我犯了一个错误,将服务添加到imports数组而不是providers数组中。

@NgModule({
  imports: [
    MyService // wrong here
  ],
  providers: [
    MyService // should add here
  ]
})
export class AppModule { }

Angular说你需要将注入对象添加到providers数组中。


我在Ubuntu中也遇到过同样的问题,因为Angular应用目录拥有根权限。将所有权更改为本地用户为我解决了这个问题。

$ sudo -i
$ chown -R <username>:<group> <ANGULAR_APP>
$ exit 
$ cd <ANGULAR_APP>
$ ng serve

我简单地把import from {AngularFirestore} from '@angular/fire/firestore'改成import from {AngularFirestore}; 来 import {AngularFirestoreModule} from '@angular/fire/firestore';

它运行得很好


对我来说,我在Ubuntu下工作

如果我在ng中使用sudo,错误就消失了

sudo ng build
sudo ng serve

更好的解决方案是使用以下命令授予当前用户对当前文件夹所需的权限:

sudo chown -R `whoami` ./

这样做将允许您在不使用sudo的情况下运行ng命令。


当使用错误的导入(例如使用autoimport)时,也会发生这种情况。让我们以MatTimePickerModule为例。这将给出一个错误信息,类似于问题中描述的错误信息:

import { NgxMatTimepickerModule } from '@angular-material-components/datetime-picker/lib/timepicker.module';

这应该是

import { NgxMatTimepickerModule } from '@angular-material-components/datetime-picker';

有时候,当你在项目中更改/更新@NgModule时,项目会被编译,但更改不会被反映出来。所以,如果你没有得到预期的结果,重新启动一次就可以了。 ng服务


对我来说,固定的是匹配角材料和适配器的版本到另一个角模块的最低版本。然后重新安装并重新运行。

    "@angular-devkit/schematics": "^10.1.2",
    "@angular/animations": "^10.1.2",
    "@angular/cdk": "^10.2.1",
    "@angular/common": "10.1.2",
    "@angular/compiler": "10.1.2",
    "@angular/core": "10.1.2",
    "@angular/forms": "10.1.2",
    "@angular/localize": "^10.1.2",
    "@angular/material": "^10.2.1",
    "@angular/material-moment-adapter": "^10.2.1",
    "@angular/platform-browser": "10.1.2",
    "@angular/platform-browser-dynamic": "10.1.2",
    "@angular/router": "10.1.2",

如你所见,我的cdk是10.2.1,我的材料也是10.2.1。 我看到使用的最低版本是10.1.2,所以我改变了版本:

    "@angular/material": "^10.1.2", (was 10.2.1)
    "@angular/material-moment-adapter": "^10.1.2", (was 10.2.1)

到10.1.2,运行"npm install",然后运行"ng serve",编译成功。


在我的情况下,我通过在tsconfig.json中设置“strictTemplates”为false来解决这个问题

{
  "compilerOptions": {
    // ...
  },
  "angularCompilerOptions": {
    "strictTemplates": false
  }
}

我之前设置为true,以防止VStudio弹出窗口显示:


当您导入一些在组件中没有使用的mat组件时,也会发生这种情况。

if you have all mat components imported in you app.module.ts you have imported some mat components and you have not used any of the components in imports and exports arrays in app.module.ts means no issues no errors will throw works fine. if you create feature module for that let say by ng g m material this will create material.module.ts filename. now we have to copy all mat import statements to newly created feature module before copying keep in mind is any import statements grayed out or not(some indication IDE shows this name is not used). if grayed out means you have to remove those names then copy and paste it to MaterialModule imports and exports array. that's solve.


我在导入mat-list。我的错误在于使用了以下语句:

import { MatList } from "@angular/material/list";
@NgModule({
  exports: [
    MatList,
  ]
})

我忘记在导入和导出声明中添加'Module'后缀。以下方法解决了这个问题:

import { MatListModule } from "@angular/material/list";
@NgModule({
  exports: [        
    MatListModule, // <-- Add 'Module' suffix here!
  ]
})

在我的例子中,问题是从一些打算重用的子模块调用. forroot()。


App.Module.ts 您可以通过在Provider中添加注入而不是导入或声明来解决这个错误。 内部Service.ts 在类上添加@injectable

ex:

@Injectable()
 export class WebApiService {   }

即使你给他们空间也不一定有用

ex:

@Injectable()


export class WebApiService {    }

尝试清除缓存

NPM缓存清理——force npm安装


如果 使用root帐户运行NPM install或yarn install 而且 使用非root帐户运行ng serve, 您将遇到这个问题。

处理: 使用root帐户启动服务器


我在创建共享指令时得到了这个错误。最初它进入了app模块的declarations数组(在我用cli运行命令后默认)。

我把它放到共享模块声明数组和导出数组中。现在,只要我从app.module.ts文件中删除它,问题就解决了。

问题是它是在两个模块(shared和app.module)中声明的。从app.module中移除,瞧!


我在Angular 12上遇到了一个问题,问题是我的同事在page模块中定义了组件,以及我们在项目中全局使用的公共模块。

从全局文件模块删除,问题解决。

关于我的情况


在我的例子中,问题在于最新的节点。我正在dockerizing Angular应用,并使用最新的节点版本,如FROM node:latest as build

要让它正常工作,请使用Angular支持的节点版本,如FROM node:14.17.4


我的错误:我错过了模块部分,我写道

import { MatPaginator } from '@angular/material/paginator';

而不是

import { MatPaginatorModule } from '@angular/material/paginator';

在我的模块里。


当您导入一个已经安装的模块,但缺少一个或多个依赖项时,可能会发生这种情况


我试图添加一个自定义管道到我的共享模块,我已经在导入和导出中添加了它。这就是为什么它会引起这个问题。

我通过将自定义管道添加到declarations:[], exports:[]和providers:[]中解决了这个问题。

我通过以下代码解决了这个问题:

@NgModule({

 declarations: [
   myCustomPipe,
 ],

 exports: [
   myCustomPipe,
 ],

 providers: [
  myCustomPipe,
 ]

})

我不知道为什么,但我能解决它的唯一方法是:

导入模块而不是组件 将文件夹名称/my-component-y/与MyComponentY匹配。我有/component-y/和mycomponent .ts

根组件是惰性加载的,因为它是用于多站点的,如果这有任何区别的话。

最好的解决方案是使用React/Next.js代替这个旧的hack框架。


重新启动visual studio代码,以便Angular语言服务重新编译包