我已按照以下说明将 lodash 安装到我的 Ionic 2 项目中:
http://mhartington.io/post/ionic2-external-libraries/
但是我编译的时候还是报了如下错误:
Error TS2307: Cannot find module 'lodash'.
在我的代码中,我按如下方式导入模块:
import * as _ from 'lodash';
我的项目可以在这里找到:https://github.com/will093/guess-game
当我运行应用程序时一切正常,所以只是 typescript 编译器认为没有 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
}
}
请帮帮我。 谢谢。
最佳答案
看起来最好的解决方案是将特定类型的 index.d.ts 的内容复制到 main.d.ts。
这帮助我解决了查询字符串 npm 包的问题。
关于即使安装了定义文件, typescript 也找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37401313/