ng add @angular/material 失败并显示“无法读取 null 的属性‘endTag’”?

Cha*_*han 6 angular-material angular

我正在尝试将 Angular Material 添加到我的 Angular 9 项目中,以便我可以使用自动完成功能。不幸的是,在遵循安装指南时,我无法完成安装 Angular Material 模块的第一步。我尝试按照此stackoverflow 帖子中列出的步骤解决该问题。这是我采取的步骤,下面是我的 package.json 供参考。

\n\n
    \n
  1. npm install --save @angular/material @angular/cdk @angular/animations
  2. \n
  3. ng add @angular/material
  4. \n
\n\n

这些命令的输出如下:

\n\n
chantelle@penny:~/projects/nereus_bos/2020-bos-frontend/bos-frontend$ npm install @angular/material --save\nnpm WARN @aws-amplify/datastore@2.1.0 requires a peer of @react-native-community/netinfo@^5.5.0 but none is installed. You must install peer dependencies yourself.\nnpm WARN @aws-amplify/core@2.3.0 requires a peer of @react-native-community/netinfo@^5.5.0 but none is installed. You must install peer dependencies yourself.\nnpm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/fsevents):\nnpm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})\nnpm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):\nnpm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})\nnpm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):\nnpm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})\n\n+ @angular/material@9.2.4\nupdated 1 package and audited 1729 packages in 10.141s\n\n54 packages are looking for funding\n  run `npm fund` for details\n\nfound 1 low severity vulnerability\n  run `npm audit fix` to fix them, or `npm audit` for details\n\nchantelle@penny:~/projects/nereus_bos/2020-bos-frontend/bos-frontend$ ng add @angular/material\nSkipping installation: Package already installed\n? Choose a prebuilt theme name, or "custom" for a custom theme: Deep Purple/Amber  [ Preview: https://material.angular.io?theme=deepp\nurple-amber ]\n? Set up global Angular Material typography styles? No\n? Set up browser animations for Angular Material? Yes\nUPDATE package.json (1563 bytes)\n\xe2\x9c\x94 Packages installed successfully.\nCannot read property \'endTag\' of null\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的package.json:

\n\n
{\n  "name": "bos-frontend",\n  "version": "0.0.0",\n  "scripts": {\n    "ng": "ng",\n    "start": "ng serve",\n    "build": "ng build",\n    "test": "ng test",\n    "lint": "ng lint",\n    "e2e": "ng e2e"\n  },\n  "private": true,\n  "dependencies": {\n    "@angular/animations": "^9.1.9",\n    "@angular/cdk": "^9.2.4",\n    "@angular/common": "~9.1.9",\n    "@angular/compiler": "~9.1.9",\n    "@angular/core": "~9.1.9",\n    "@angular/forms": "~9.1.9",\n    "@angular/localize": "~9.1.7",\n    "@angular/material": "^9.2.4",\n    "@angular/platform-browser": "~9.1.9",\n    "@angular/platform-browser-dynamic": "~9.1.9",\n    "@angular/router": "~9.1.9",\n    "@aws-amplify/pubsub": "^2.1.1",\n    "@ng-bootstrap/ng-bootstrap": "^6.1.0",\n    "aws-amplify": "^3.0.11",\n    "bootstrap": "^4.5.0",\n    "jquery": "^3.5.1",\n    "ngx-spinner": "^9.0.2",\n    "popper.js": "^1.16.1",\n    "rxjs": "~6.5.4",\n    "tslib": "^1.10.0",\n    "zone.js": "~0.10.2"\n  },\n  "devDependencies": {\n    "@angular-devkit/build-angular": "~0.901.7",\n    "@angular/cli": "~9.1.7",\n    "@angular/compiler-cli": "~9.1.9",\n    "@types/node": "^12.11.1",\n    "@types/jasmine": "~3.5.0",\n    "@types/jasminewd2": "~2.0.3",\n    "codelyzer": "^5.1.2",\n    "jasmine-core": "~3.5.0",\n    "jasmine-spec-reporter": "~4.2.1",\n    "karma": "~5.0.0",\n    "karma-chrome-launcher": "~3.1.0",\n    "karma-coverage-istanbul-reporter": "~2.1.0",\n    "karma-jasmine": "~3.0.1",\n    "karma-jasmine-html-reporter": "^1.4.2",\n    "protractor": "~5.4.3",\n    "ts-node": "~8.3.0",\n    "tslint": "~6.1.0",\n    "typescript": "~3.8.3"\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

isu*_*ekb 1

该错误可能是由重复的结束标记引起的。

检查您的 .html 文件,删除重复的结束标记,例如</html>,</body>.