gpt4 book ai didi

javascript - NW.js 无法导出模块

转载 作者:行者123 更新时间:2023-12-04 08:08:48 26 4
gpt4 key购买 nike

我正在尝试使用 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.js然后 gkmaudio-stream-meter停止工作以及我的其他代码。
View the full source code here

最佳答案

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

  • https://github.com/bomeers/Bird-Brain/pull/1

  • 不过这里的主要问题是 module.exports不是函数,它会被分配一个对象,例如:
    module.exports = { doSomething };
    而且您的导入路径与 CWD 无关
    const exportable = require("../app/twitchAuth.js");

    关于javascript - NW.js 无法导出模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66082934/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com