简体   繁体   English

错误:模块“AppModule”导入的意外值“HttpClient”。 请添加@NgModule 注释

[英]Error: Unexpected value 'HttpClient' imported by the module 'AppModule'. Please add a @NgModule annotation

Error: Unexpected value 'HttpClient' imported by the module 'AppModule'.错误:模块“AppModule”导入的意外值“HttpClient”。 Please add a @NgModule annotation.请添加@NgModule 注释。

I do not understand why I am getting this error.我不明白为什么我会收到这个错误。

I have tried both: import { HttpClient } from '@angular/common/http';我都试过: import { HttpClient } from '@angular/common/http'; and import { HttpClientModule } from '@angular/common/http';并从 '@angular/common/http' 导入 { HttpClientModule };

This is the full error:这是完整的错误:

Error: Unexpected value 'HttpClient' imported by the module 'AppModule'. Please add a @NgModule annotation.
at syntaxError (http://localhost:8100/build/vendor.js:116430:34)
at http://localhost:8100/build/vendor.js:131184:44
at Array.forEach (<anonymous>)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:8100/build/vendor.js:131159:49)
at JitCompiler._loadModules (http://localhost:8100/build/vendor.js:150357:87)
at JitCompiler._compileModuleAndComponents (http://localhost:8100/build/vendor.js:150318:36)
at JitCompiler.compileModuleAsync (http://localhost:8100/build/vendor.js:150212:37)
at CompilerImpl.compileModuleAsync (http://localhost:8100/build/vendor.js:115251:49)
at PlatformRef.bootstrapModule (http://localhost:8100/build/vendor.js:5952:25)
at Object.491 (http://localhost:8100/build/main.js:2405:109)

Ionic Framework 3.9.2 Ionic Native: ^2.9.0 Ionic App Scripts: 3.2.4 Angular Core: 5.2.11 Angular Compiler CLI: 5.2.11 Node: 8.10.0 OS: Windows 10 Ionic Framework 3.9.2 Ionic Native:^2.9.0 Ionic App Scripts:3.2.4 Angular Core:5.2.11 Angular Compiler CLI:5.2.11 Node:8.10.0 OS:Windows 10

You need import HttpClientModule, example:您需要导入 HttpClientModule,例如:

 import { HttpClientModule } from '@angular/common/http';

 @NgModule({
   imports: [
     BrowserModule,
     // import HttpClientModule after BrowserModule.
     HttpClientModule,
  ],
  declarations: [
     AppComponent,
  ],
  bootstrap: [ AppComponent ]
})

export class AppModule {}

Read: Angula HttpClient阅读: Angula HttpClient

Error: Unexpected value 'HttpClient' imported by the module 'AppModule'.错误:模块'AppModule'导入了意外的值'HttpClient'。 Please add a @NgModule annotation.请添加一个@NgModule批注。

I do not understand why I am getting this error.我不明白为什么会收到此错误。

I have tried both: import { HttpClient } from '@angular/common/http';我都尝试过:从'@ angular / common / http'导入{HttpClient}; and import { HttpClientModule } from '@angular/common/http';并从'@ angular / common / http'导入{HttpClientModule};

This is the full error:这是完整的错误:

Error: Unexpected value 'HttpClient' imported by the module 'AppModule'. Please add a @NgModule annotation.
at syntaxError (http://localhost:8100/build/vendor.js:116430:34)
at http://localhost:8100/build/vendor.js:131184:44
at Array.forEach (<anonymous>)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:8100/build/vendor.js:131159:49)
at JitCompiler._loadModules (http://localhost:8100/build/vendor.js:150357:87)
at JitCompiler._compileModuleAndComponents (http://localhost:8100/build/vendor.js:150318:36)
at JitCompiler.compileModuleAsync (http://localhost:8100/build/vendor.js:150212:37)
at CompilerImpl.compileModuleAsync (http://localhost:8100/build/vendor.js:115251:49)
at PlatformRef.bootstrapModule (http://localhost:8100/build/vendor.js:5952:25)
at Object.491 (http://localhost:8100/build/main.js:2405:109)

Ionic Framework 3.9.2 Ionic Native: ^2.9.0 Ionic App Scripts: 3.2.4 Angular Core: 5.2.11 Angular Compiler CLI: 5.2.11 Node: 8.10.0 OS: Windows 10 Ionic Framework 3.9.2 Ionic本机:^ 2.9.0 Ionic应用程序脚本:3.2.4 Angular Core:5.2.11 Angular编译器CLI:5.2.11节点:8.10.0操作系统:Windows 10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 2模块“ AppModule”声明的异常值“ MyDirective” - Angular 2 Unexpected value 'MyDirective' declared by the module 'AppModule' 请添加@NgModule 注释,但我不知道为什么 - Please add a @NgModule annotation but I cannot figure why 错误中的错误:AppModule不是NgModule-Angular-cli - ERROR in Error: AppModule is not an NgModule - Angular-cli 编译器失败 - 找不到“AppModule”的 NgModule 元数据中的错误 - Compiler fails - ERROR in No NgModule metadata found for 'AppModule' error NG6002:出现在AppModule的NgModule.imports中,但本身有错误 - error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors 请在 Angular 6 中添加 @Pipe/@Directive/@Component 注释 - Please add a @Pipe/@Directive/@Component annotation in Angular 6 Ng Build --prod 错误并带有“请添加 &gt; @Pipe/@Directive/@Component 注释”消息 - Ng Build --prod Error with “Please add a > @Pipe/@Directive/@Component annotation” Message 在ngModule导入中找不到模块 - Module not found in ngModule imports 出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule class. in Angular 12.2.9 - Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class. in Angular 12.2.9 npm构建失败:模块声明的意外值“ undefined”错误 - npm build failed: ERROR in Unexpected value 'undefined' declared by the module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM