Unexpected Token error while using Inquirer.js module in Node JS

45 views Asked by At

I am using Inquirer.JS in my Node project. It returns an unexpected token error. My code is:

import inquirer from 'inquirer';

inquirer
  .prompt([
    {
        message: "Type in your URL",
        name: "URL",
    },
    ])
  .then((answers) => {
    console.log(answers);
  })
  .catch((error) => {
    if (error.isTtyError) {
      // Prompt couldn't be rendered in the current environment
    } else {
      // Something else went wrong
    }
  });

Error is:

file:///C:/Users/LINU/Desktop/StudyNotes/qr-code-generator/node_modules/inquirer/lib/prompts/expand.js:100
    input ||= this.rawDefault;
          ^^^

SyntaxError: Unexpected token '||='
    at Loader.moduleStrategy (internal/modules/esm/translators.js:145:18)

How to fix this?

1

There are 1 answers

0
Linu S On

I found the solution myself.

install this version

npm install --save inquirer@^8.0.0

and use

const inquirer = require('inquirer');