18

在遵循 update.angular.io 上的更新指南(+ 运行 npm 更新)并尝试使用ng serve我得到以下错误编译网站后,我正在将我的项目从 Angular 8 更新到 9:

ERROR in Failed to compile entry-point angular-font-awesome (es2015 as esm2015) due to compilation errors:
node_modules/angular-font-awesome/dist/angular-font-awesome.js:3968:26 - error NG1010: Value at position 0 in the NgModule.imports of AngularFontAwesomeModule is not a reference: [object Object]

3968                 imports: [CommonModule],

任何帮助表示赞赏。

更新

我的ng version输出:

   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 9.0.2
Node: 12.13.1
OS: win32 x64

Angular: 9.0.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.2
@angular-devkit/build-angular     0.900.2
@angular-devkit/build-optimizer   0.900.2
@angular-devkit/build-webpack     0.900.2
@angular-devkit/core              9.0.2
@angular-devkit/schematics        9.0.2
@angular/cdk                      9.0.0
@angular/cli                      9.0.2
@angular/material                 9.0.0
@ngtools/webpack                  9.0.2
@schematics/angular               9.0.2
@schematics/update                0.900.2
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2

我的 package.json:

{
  "name": "avior",
  "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/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",
    "@fortawesome/fontawesome": "^1.1.8",
    "@ngtools/webpack": "^9.0.2",
    "angular-font-awesome": "^3.1.2",
    "angular-tree-component": "^8.5.4",
    "bootstrap": "^4.4.1",
    "chromedriver": "^79.0.3",
    "core-js": "^2.6.11",
    "font-awesome": "^4.7.0",
    "fontawesome": "^5.6.3",
    "gitignore": "^0.6.0",
    "jquery": "^3.4.1",
    "moment": "^2.24.0",
    "popper.js": "^1.16.1",
    "rxjs": "^6.5.4",
    "tslib": "^1.10.0",
    "webdriver-manager": "^12.1.7",
    "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/jasmine": "~2.8.8",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "^12.11.1",
    "angular-ide": "^0.9.73",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "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",
    "protractor": "^5.4.3",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "^3.7.5"
  }
}

我的 tsconfig.ts:

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

更新 2 卸载angular-font-awesome软件包后,我只收到一个 Angular 插件错误:

ERROR in Failed to compile entry-point angular-tree-component (module as esm5) due to compilation errors:
node_modules/mobx-angular/dist/mobx-angular.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of TreeModule, but could not be resolved to an NgModule class

8 export declare class MobxAngularModule {
4

2 回答 2

22

如果你想在 Angular 9+ 中使用 font-awesome,你可以使用这个命令:

 ng add @fortawesome/angular-fontawesome

归功于FortAwesome

于 2020-02-22T18:41:13.060 回答
13

因此,使用删除 angular-font-awesomenpm uninstall angular-font-awesome并使用添加新包ng add @fortawesome/angular-fontawesome@0.6.0,然后通过添加禁用 IVY 编译器

"angularCompilerOptions": {
    "enableIvy": false
  }

进入 tsconfig.app.json 和 ts.spec.json 似乎已经解决了这些问题。

于 2020-02-13T12:50:42.013 回答