找不到名字'HttpClient',如何解决这个错误?

时间:2017-08-04 11:03:31

标签: angular

当我尝试使用npm start启动项目时出现错误:

[at-loader] Checking finished with 1 errors
[at-loader] ./node_modules/@ngx-translate/http-loader/src/http-loader.d.ts:10:23 
    TS2304: Cannot find name 'HttpClient'. 

我尝试替换http: HttpClient上的http: Http,同时重新安装@ngx-translate

我已安装:"@angular/common": "~4.1.2"

如何解决?

3 个答案:

答案 0 :(得分:3)

“@ angular / http”中的Tilde:“~4.1.2”表示您只允许安装最新的补丁(例如4.1.3,4.1.4等)。

更新你的package.json以包含以下依赖项(^ 4.0.0中的帽子符号将采用最新的次要版本,即4.3):

[client 111.111.111.111:51008] script '/srv/www/htdocs/wwwuni/fileadmin/Dokumente/index.php' not found or unable to stat

然后删除node_modules目录并运行npm install。

答案 1 :(得分:1)

我面对这个' HttpClient'今天的问题,但我正在使用离子。对于那些开发人员,解决方案是使用以前版本的http-loader。

  

$ npm install @ ngx-translate / core @ ngx-translate / http-loader @ 0.1.0 --save

另请参阅:https://github.com/ngx-translate/core/issues/629

答案 2 :(得分:-2)

检查node_modules中是否有@ angular / http。 如果没有,请安装它。