gpt4 book ai didi

angular - 为什么我得到 "Cannot find name ' NgModule '"despite running "npm i @types/node --global”?

转载 作者:行者123 更新时间:2023-12-04 02:48:30 26 4
gpt4 key购买 nike

尽管遵循此处的建议- TypeScript error in Angular2 code: Cannot find name 'module' ,我仍然收到此错误。我正在使用 Angular 5 和 npm 6.9.0。我正在尝试在这里完成本教程 -- https://medium.freecodecamp.org/learn-how-to-create-your-first-angular-app-in-20-min-146201d9b5a7 .

我在 ./src/app/app.component.ts 文件的顶部有这个

import { Component,trigger,animate,style,transition,keyframes } from '@angular/core';
import { FormsModule } from '@angular/forms';

@NgModule({
imports: [
BrowserModule,
FormsModule //<----------make sure you have added this.
],
})

但是当我运行我的应用程序时出现错误
localhost:todo-app davea$ ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2019-05-17T17:06:29.377Z
Hash: e9b5158cd1cb6d5685c7
Time: 2561ms
chunk {inline} inline.bundle.js (inline) 3.85 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 2.91 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 577 bytes [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 41.6 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 867 kB [initial] [rendered]

ERROR in src/app/app.component.ts(4,2): error TS2552: Cannot find name 'NgModule'. Did you mean 'module'?
src/app/app.component.ts(6,14): error TS2304: Cannot find name 'BrowserModule'.

我还需要做什么才能让 NgModule 得到认可?

最佳答案

这个错误,Cannot find name 'NgModule' , 是因为没有导入 NgModule来自 @angular/core .将其添加到第一行将解决问题。

关于angular - 为什么我得到 "Cannot find name ' NgModule '"despite running "npm i @types/node --global”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56190863/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com