【问题标题】:Error when serving an Angular application with Firebase Authentication使用 Firebase 身份验证为 Angular 应用程序提供服务时出错
【发布时间】:2021-08-22 10:12:06
【问题描述】:

我正在尝试为我的 Angular 应用程序提供服务,该应用程序具有路由和 Firebase 身份验证,但我收到此错误:

Error: node_modules/@angular/fire/auth/auth.d.ts:15:22 - error NG6002: Appears in
the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/fire/auth) which declares AngularFireAuth 
has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check
if a newer version of the library is available, and update if so. Also consider checking
with the library’s authors to see if the library is expected to be compatible with Ivy.

我不知道如何解决这个问题,因为我尝试更新库(实际上,我尝试更新所有库)但没有成功。 (须藤 npm 更新)。

你有什么想法吗?

非常感谢您。

【问题讨论】:

  • 问题可能与 ES2015 和可能发生的重新编译有关,具体取决于 Angular 版本和库。从 package.jsonangular.json 脚本级别添加版本可能会有所帮助。
  • 我会按照您的建议尝试修改 package.json 和 angular.json。非常感谢您的帮助!

标签: angular typescript firebase npm


【解决方案1】:

顺便说一下,这是我的 angular.json 和 package.json 文件:

angular.json

{


"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "AngularCRUD2": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/AngularCRUD2",
            "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": [
              "src/styles.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "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": "AngularCRUD2:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "AngularCRUD2:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "AngularCRUD2: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": [
              "src/styles.css"
            ],
            "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": "AngularCRUD2:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "AngularCRUD2:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "AngularCRUD2"
}

package.json

  {
  "name": "angular-crud2",
  "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",
    "@angular/common": "9",
    "@angular/compiler": "9",
    "@angular/core": "9",
    "@angular/fire": "^6.1.5",
    "@angular/forms": "9",
    "@angular/platform-browser": "9",
    "@angular/platform-browser-dynamic": "9",
    "@angular/router": "9",
    "firebase": "^8.6.5",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.11.3"
  },
  "devDependencies": {
    "@angular-devkit/architect": "9",
    "@angular-devkit/build-angular": "9",
    "@angular/cli": "9",
    "@angular/compiler-cli": "9",
    "@firebase/analytics": "^0.3.6",
    "@firebase/app": "^0.6.5",
    "@types/jasmine": "~3.6.0",
    "@types/node": "^12.11.1",
    "codelyzer": "^6.0.0",
    "firebase-tools": "^8.0.0 || ^9.0.0",
    "fuzzy": "^0.1.3",
    "inquirer": "^6.2.2",
    "inquirer-autocomplete-prompt": "^1.0.1",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "jsonc-parser": "^3.0.0",
    "karma": "~6.1.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "~1.5.0",
    "open": "^7.0.3",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.1.5"
  }
}
  • 在尝试使用默认版本值后,我将某些版本值指定为“9”。

【讨论】:

    【解决方案2】:

    我也遇到了这个错误,当我从 appmodule 中删除 angularfireauth 导入时,它已得到修复。你只需要在服务或者你需要的组件中导入就可以了

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 2020-04-23
      • 2017-02-21
      • 2014-09-28
      • 2018-10-31
      • 2019-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多