【问题标题】:NW.js trouble exporting modulesNW.js 导出模块时遇到问题
【发布时间】:2021-02-06 23:09:11
【问题描述】:

我正在尝试使用module.exports() 在我的 NW.js 应用程序中创建一个新模块。

我有两个正在使用的文件:

Index.js

const gkm = require('gkm'); //This is a key listener
const AudioStreamMeter = require('audio-stream-meter'); //This is a mic listener
const exportable = require("./twitchAuth.js");

exportable.test();
// More code under this

twitchAuth.js

function doSomething() {
    document.getElementById("volume").style.backgroundColor = "#FFF";
}

module.exports(doSomething);

唯一的问题是,当我将 const exportable = require("./separateFile.js"); 添加到 index.js 时,gkmaudio-stream-meter 和我的其余代码一样停止工作。

View the full source code here

【问题讨论】:

    标签: javascript node-webkit nwjs module.exports


    【解决方案1】:

    我创建了一个 PR 来修复 repo 中的一堆东西:

    这里的主要问题是 module.exports 不是一个函数,它会被分配一个对象,例如:

    module.exports = { doSomething };
    

    您的导入路径与 CWD 无关

    const exportable = require("../app/twitchAuth.js");
    

    【讨论】:

      猜你喜欢
      • 2012-01-07
      • 2020-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-21
      • 1970-01-01
      • 2021-07-24
      相关资源
      最近更新 更多