0

我正在尝试从一个文件中导出一个名为 start 的函数。当我在另一个文件中需要它时,我在实例化它时得到“开始不是函数”。

我试过使它成为一个同步函数,但无济于事。

应用程序.js:

const start = async () => {
  await init();
  inquirer
    .prompt([
      {
        type: 'list',
        name: 'startmenu',
        message: 'Choose one: ',
        choices: ['Login', 'Register']
      }
    ])
      .then((answer) => {
        if (answer.startmenu === 'Login') {
          return login();
        } else {
          return register();
        };
    });
};

module.exports = start;

playGame.js:

const start = require('../app');

const logOut = () => {
  return start();
}

我得到的错误:

(node:47030) UnhandledPromiseRejectionWarning: TypeError: start is not a function
    at logOut (/Users/rjshoemaker/Desktop/code/projects/terminalscape/gamefiles/playGame.js:169:10)
    at inquirer.prompt.then (/Users/rjshoemaker/Desktop/code/projects/terminalscape/gamefiles/playGame.js:86:20)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
4

0 回答 0