从IIFE中的另一个模块请求函数会返回错误`TypeError:require...不是函数`

问题描述

我正在从名为scraper.js的模块中导入一个函数,如下所示:

module.exports = getCategories

这是从另一个模块中的异步IIFE内部导入的:

(async () => {
    try {
        const scraper = await require('./scraper')();
        console.log(scraper)
    } catch (err) {
        console.log(err)
    }
})();

这将返回以下错误

(async () => {
^

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)