我正在使用一个文件中的一个函数,在另一个文件中,并在那里调用它。这导致该函数在从命令行运行时同时运行两次,但在我在 VSCode 中运行时却没有。
这是一个例子:
// fileOne
async function task() {
console.log('Hello')
}
module.exports = { task }
// fileTwo
const fileOne = require('./fileOne');
fileOne.task();
在 VSCode 中运行时的输出:
Hello
在命令行中运行时的输出:
Hello
Hello
我不确定为什么会这样……不,我不是偶然在 fileOne 中调用它,因为那样它也会在 VSCode 中运行两次。
谢谢。