0

start という関数を 1 つのファイルからエクスポートしようとしています。他のファイルに要求すると、インスタンス化すると「開始は関数ではありません」と表示されます。

私はそれを同期関数にしようとしましたが、役に立ちませんでした。

app.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