Angular Field ‘browser’ doesn’t contain a valid alias configuration报错

最近Angular项目引用httpClient后报错:

ERROR in ./src/app/app.module.ts
Module not found: Error: Can't resolve '@angular/common/http/src/module' in '/Users/xxx/Desktop/projects/angular/xxx/src/app'
resolve '@angular/common/http/src/module' in '/Users/xxx/Desktop/projects/angular/xxx/src/app'
  Parsed request is a module
  using description file: /Users/xxx/Desktop/projects/angular/xxx/package.json (relative path: ./src/app)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /Users/xxx/Desktop/projects/angular/xxx/package.json (relative path: ./src/app)

经发现是httpclient引用错了
将:

import {HttpClientModule} from "@angular/common/http/src/module";

改为

@angular/common/http

即可

Leave a Reply