【发布时间】:2016-09-20 22:38:24
【问题描述】:
我已按照以下说明将 lodash 安装到我的 Ionic 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
}
}
请帮助我。 谢谢。
【问题讨论】:
-
你的 node_modules 文件夹中有 lodash 文件夹吗?
-
是的,代码运行良好并且能够找到 lodash。打字稿编译器只是认为该模块不存在,应该通过包含定义文件来修复它,但由于某种原因不是。
-
看起来最好的解决方案是将特定类型的 index.d.ts 的内容复制到 main.d.ts forum.ionicframework.com/t/… 这帮助我解决了查询字符串 npm 包的问题。
标签: typescript ionic2