2

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

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

索引.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.jsthengkmaudio-stream-meter停止工作以及我的其他代码时。

在此处查看完整的源代码

4

1 回答 1

2

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

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

module.exports = { doSomething };

而且您的导入路径与 CWD 无关

const exportable = require("../app/twitchAuth.js");
于 2021-02-07T06:15:52.997 回答