TypeError: require(...).connect is not a function

TypeError: require(...).connect is not a function

node version: v4.4.4
npm version: 3.9.2
ionic version (app): 2.0.0-beta.7
amqplib version: 0.4.1

我目前正在尝试使用 Ionic 2 框架开发一个应用程序,我决定在 this library. Feel free to inspect the code here 中使用 RabbitMQ 在我的应用程序中引入消息传递以供进一步参考。

  1. 首先,我使用 npm install https://github.com/squaremo/amqp.node.git 手动安装了库,因为发布版本来自 npm is outdated

  2. 之后,我通过 typings install dt~amqplib --global --save 添加了库的 Typescript 定义。

  3. 我为我的应用程序创建了一个名为 Page2 的新页面,其中导入了库...

    import * as amqp from 'amqplib/callback_api';
    [...]
    

    ...并用于连接到服务器...

    [...]
    setConnection() {
        amqp.connect(this.connectionUrl, (err: any, connection: amqp.Connection) => {
            this.connection = connection;
            this.connection.createChannel((err: any, channel: amqp.Channel) => {
                this.channel = channel;
                this.channel.assertExchange(this.exchange, 'topic', { durable: false });
            });
        });
    }
    [...]
    
  4. 当我尝试 运行 时出现问题(我使用 emulatornative设备 运行宁Android)。如果我尝试点击 Set connection 按钮,我会收到以下错误:

错误与库中 connect.js file. Is there any trouble with NodeJS Net 模块的 sock = require('net').connect(sockopts, onConnect); 行有关,还是我在应用程序中的某处配置错误?提前致谢。

您的图书馆可以使用的离子应用程序中没有 nodeJS 服务器。