每次我从“@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
,然后再次运行 npm install
。足够了,它有效。
关于javascript - 由于错误,无法使用 Angular FormsModule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66731024/