返回带有对象的模块导出 - 错误异步函数



我创建了一个帮助程序来存储我的所有数据,并希望导入它。虽然,它要么以未定义的形式出现,要么以[AsyncFunction]的形式出现。

我正在使用 Express,导入它的方式可能存在冲突。不确定。

标签.js

module.exports = () => {
return {
'test',
'test1',
'test3'
}

主.js

const allTags = require('../../src/helpers/tags')
router.get('/test8', (req, res) => {
console.log( allTags ) // [AsyncFunction]
})

如果我添加allTags()则结果不会'Promise { undefined } '

您不需要导出函数,只需导出数组本身即可。

module.exports = [
'test',
'test1',
'test3'
]

最新更新