【问题标题】:error TS2307: Cannot find module 'bluebird'错误 TS2307:找不到模块“蓝鸟”
【发布时间】:2016-08-29 22:41:58
【问题描述】:

我目前正在尝试使用 Ionic 2Angular 2Typescript 版本 开发应用程序。我决定使用库 amqp-ts 在我的应用程序中包含消息传递。我通过 npm 安装了该库,例如:

npm install amqp-ts

一切都很好,现在我得到了这样的东西:

/ app root directory
+ node_modules
    - amqp-ts
        - lib 
            -  amqp-ts.d.ts
        - node_modules
            -  amqplib
            -  bluebird
            -  winston

问题现在开始:我将库导入到我的组件中,就像在 the documentation 的示例中所做的那样...

import * as Amqp from "amqp-ts";

...当我尝试部署应用程序时,我收到下一条错误消息:

TypeScript error: C:/APPs/Test/Ionic2Angular2App/node_modules/amqp-ts/lib/amqp-ts.d.ts(2,26): Error TS2307: Cannot find module 'bluebird'.
TypeScript error: C:/APPs/Test/Ionic2Angular2App/node_modules/amqp-ts/lib/amqp-ts.d.ts(50,12): Error TS2304: Cannot find name 'Buffer'.

1.与第一条错误消息相关的行

// exported Typescript type definition for AmqpSimple
import * as Promise from "bluebird";
[...]

2。与第二条错误消息相关的行(同一文件:amqp-ts.d.ts)

export class Message {
    content: Buffer;
    [...]
}

我希望你能帮助我,拜托。

【问题讨论】:

  • 你安装了那个库的类型吗?

标签: node.js import typescript angular


【解决方案1】:

除了常规包安装之外,您还需要安装 TypeScript 类型。类型就像头文件,它们包含所有方法/类/接口定义。

要安装类型,您需要一个类型工具。最好的方法是全局安装,这样你就可以在每个项目中使用它

npm install typings --global

然后在你的项目中安装新的类型非常简单,首先搜索库:

typings search bluebird

安装它:

typings install --save bluebird

更多信息:https://github.com/typings/typings

【讨论】:

  • 非常感谢,它解决了第一个错误消息。我还有第二个(“找不到名称缓冲区”),知道吗?
  • 同样的东西,你需要知道哪个库提供了缓冲区类型。 Buffer 是 NodeJS 内部的东西,所以最好的办法是安装 nodejs 分型typings install --save node
  • 无论如何,我看到这个 ampq lib 仍然使用 TSD (github.com/abreits/amqp-ts/blob/master/tsd.json),检查 TSD 文档中的 Typings/migration,它应该可以帮助您解决未来的问题(可能会丢失下一个错误winstonwhen 打字)。我不确定如何处理Typings,因为我也绑定到 TSD,但例如尝试引用 node_modules/ampq-ts/libs/typings/tsd.d.ts 文件 (<reference path="..." />)
猜你喜欢
  • 2015-10-01
  • 1970-01-01
  • 2018-08-29
  • 2017-03-30
  • 2019-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
相关资源
最近更新 更多