将Node.js模块添加到Cordova App

时间:2016-01-07 15:32:04

标签: javascript node.js cordova npm windows-10-mobile

我想将Discord.io添加到我的cordova(Windows 10移动版)应用中。

我在cordova项目目录中执行了npm install discord.io。 它创建node_modules目录,并将discord.io添加到NPM-Dependencies:

Project-Explorer

如果我尝试初始化discord.io lib,就像GitHub中的例子那样:

var DiscordClient = require('discord.io');
var bot = new DiscordClient({
    autorun: true,
    email: "my@email.com",
    password: "secret_passw0rd"
});

bot.on('ready', function() {
    console.log(bot.username + " - (" + bot.id + ")");
});

bot.on('message', function(user, userID, channelID, message, rawEvent) {
    if (message === "ping") {
        bot.sendMessage({
            to: channelID,
            message: "pong"
        });
    }
});

我收到错误消息:

0x800a1391 - JavaScript runtime error: 'require' is undefined

我还尝试使用cordova.require('discord.io');,导致此错误:

0x800a139e - JavaScript runtime error: module discord.io not found

如何正确包含和初始化此库?

0 个答案:

没有答案