angular - Angular 实践与英雄之旅和 AppRoutingModule 中的错误
问题描述
我用 Angular Tour of Heroes练习。一切都很好,直到app-routing.module部分。按照说明添加和编辑 app-routing.module.ts 后出现错误。即使我从最终代码审查中复制并粘贴所有代码, 仍然会出现相同的错误。
Error: ./node_modules/@angular/router/__ivy_ngcc__/fesm2015/router.js 43:12
Module parse failed: Identifier 'ɵngcc0' has already been declared (43:12)
File was processed with these loaders:
* ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
* ./node_modules/@ngtools/webpack/src/ivy/index.js
You may need an additional loader to handle the result of these loaders.
| import * as ɵngcc0 from '@angular/core';
| import * as ɵngcc1 from '@angular/common';
> import * as ɵngcc0 from '@angular/core';
| import * as ɵngcc1 from '@angular/common';
| class RouterEvent {
包.json
{
"name": "angular-tour-of-heroes",
"version": "0.0.0",
"private": true,
"dependencies": {
"@angular/animations": "~11.2.4",
"@angular/common": "~11.2.4",
"@angular/compiler": "~11.2.4",
"@angular/core": "~11.2.4",
"@angular/forms": "^11.2.4",
"@angular/platform-browser": "~11.2.4",
"@angular/platform-browser-dynamic": "~11.2.4",
"@angular/router": "~11.2.4",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.11.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1102.3",
"@angular/cli": "~11.2.3",
"@angular/compiler-cli": "~11.2.4",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.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",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.1.5"
}
}
解决方案
I have a workaround, It's not the proper solution but it works for me. Solution is to open file node_modules@angular\router_ivy_ngcc_\fesm2015\router.js
import * as ɵngcc0 from '@angular/core';
import * as ɵngcc1 from '@angular/common';
// import * as ɵngcc0 from '@angular/core';
// import * as ɵngcc1 from '@angular/common';
comment above two lines that are repeated. for me, it's lines 43 and 44. And restart your Angular Application. It will work!
推荐阅读
- reactjs - Gatsbyjs 在布局中加载不同的标题
- syntax-error - REPL 模式下的 ocaml 语法错误
- matlab - 为什么 innerjoin 在 parfor 中不起作用
- c++ - 在一系列方程上使用 boost::bisect
- java - JPanel 和 GridBagLayout
- c# - 格式化 Windows 窗体文本框显示
- javascript - 使用 React 和 Redux 传播运算符错误
- python - *map 函数在 python 中的作用是什么?
- python - Python tkinter canvas自定义用户输入程序不起作用
- node.js - 块(缓冲区)从节点 js 中的文件(文本文件)的 ReadStreaming 中携带的数据量?