即使安装了定义文件, typescript 也找不到模块

标签 typescript ionic2

我已按照以下说明将 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。

https://forum.ionicframework.com/t/gulp-fails-on-type-definitions-added-via-typings-while-vs2015-has-no-problem/52497/4

这帮助我解决了查询字符串 npm 包的问题。

关于即使安装了定义文件, typescript 也找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37401313/

相关文章:

javascript - 从状态数组中删除对象

angular - 如何以 Angular 4 发射事件发射器?

ionic-framework - API错误:<_ UIKBCompatInputView:0x13fd1d7c0;框架=(0 0; 0 0);假设UIViewNoIntrinsicMetric,layer = <CALayer:0x1c4426e40 >>返回0宽度

javascript - Observable.of 对图像 src 中的管道不返回任何内容

cordova - 使用 cordova-plugin-camera 显示图像

typescript - 在 Typescript 中使数组元素可为空

angular - 如何使用 ion-col 响应式设置大型动态表数据

angular - 如何在 Ionic 2 项目上运行 Sonar 扫描仪

规范化数据的 TypeScript 类型或接口(interface)

angular - 如何在 Ionic 2 中将数据从一个页面传递到另一个页面以进行导航