【发布时间】:2021-03-21 10:06:32
【问题描述】:
每次我从“@angular/forms”导入 FormsModule 时,都会出现以下错误:
Error: ./node_modules/@angular/forms/__ivy_ngcc__/fesm2015/forms.js 27:12
Module parse failed: Identifier 'ɵngcc0' has already been declared (27: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 ɵngcc0 from '@angular/core';
| const NG_VALUE_ACCESSOR = new InjectionToken('NgValueAccessor');
|
这是我的一段代码:
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
这个问题的一个有趣点是,如果我没有在导入列表中包含 FormsModule,代码可以正常工作,但是当它在列表中时,它会导致问题。简单的导入 FormsModule 似乎不是问题。
我该如何解决?
【问题讨论】:
-
尝试运行
npm ci和 w8 直到结果出现在您的应用程序中 -
你能分享你的
package.json文件吗? -
能否请您删除 node_module 文件夹并再次运行 npm install 命令?
-
npm ci解决了这个问题。谢谢!我认为删除 node_module 文件夹会产生相同的效果。无论如何,谢谢大家的帮助!
标签: javascript angular webpack