2016-05-23 98 views
2

我按照下面的说明安装lodash到我的离子2项目:打字稿找不到模块即使定义文件安装

http://mhartington.io/post/ionic2-external-libraries/

但我仍然得到以下错误编译时:

错误TS2307:无法找到模块'lodash'。

在我的代码,我导入模块如下:

import * as _ from 'lodash'; 

我的项目可以在这里找到:https://github.com/will093/guess-game

一切工作正常,当我运行的应用程序,所以它只是打字稿编译器认为没有lodash模块。我能想到的最有可能的是,这个问题是我的tsconfig文件,但据我可以看到filesGlob不包括我的定义文件:

{ 
    "compilerOptions": { 
     "target": "es5", 
     "module": "commonjs", 
     "emitDecoratorMetadata": true, 
     "experimentalDecorators": true 
    }, 
    "filesGlob": [ 
     "**/*.ts", 
     "!node_modules/**/*" 
    ], 
    "exclude": [ 
     "node_modules", 
     "typings/main", 
     "typings/main.d.ts" 
    ], 
    "compileOnSave": false, 
    "atom": { 
     "rewriteTsconfig": false 
    } 
} 

请帮助我。 谢谢。

+0

在你的node_modules文件夹里面有一个lodash文件夹吗? –

+0

是的,代码运行得很好,能够找到lodash。打字稿编译器只是认为模块不在那里,应该通过包含定义文件来解决这个问题,但是由于某些原因不能。 – user2961850

+0

看起来最好的解决方案是将index.d.ts的内容复制到main.d.ts https://forum.ionicframework.com/t/gulp-fails-on-type-definitions -added-via-typings-while-vs2015-has-no-problem/52497/4 这帮我解决了我的查询字符串npm包的问题。 –

回答