导出函数不会使其在其他模块中可用

问题描述 投票:0回答:1

我正在尝试使用 cli_config.js 中的retrieve_endpoints 函数。 我将函数添加到模块导出中,并在 cli_config 文件中添加了 require。 为什么我似乎无法调用retrieve_endpoints函数?

collector.js


async function retrieve_endpoints(enviromnent) {
    let configured_endpoints = []; 

    return configured_endpoints;
}



module.exports = ({ server }) => {
    return {
        retrieve_endpoints
    };
}

cli_config.js


const collector = require('../collector/collector');



function webapi_source({ menus }) {
    endpoints = await collector.retrieve_endpoints(env);
            
}
javascript node.js node-modules
1个回答
0
投票

您的 webapi_source 函数中的问题是您尝试使用 wait 关键字而不将该函数标记为异步。

async function webapi_source({ menus }) {
    endpoints = await collector.retrieve_endpoints(env);
}
© www.soinside.com 2019 - 2024. All rights reserved.