Last modified: Jun 28, 2026
Fix Cannot Find Module Inquirer
Encountering the Cannot find module 'inquirer' error is common when working with Node.js command-line tools. This error stops your script from running. It happens when Node.js cannot locate the inquirer package in your project or globally.
This guide will show you simple steps to resolve the error. You'll learn why it occurs and how to prevent it in the future.
What Causes This Error?
The error occurs for a few main reasons. The inquirer package is not installed. Or it is installed in a different location than expected. Sometimes, the node_modules folder is missing or corrupted. Another cause is using a different version of Node.js than when the package was installed.
Let's look at each cause and how to fix it.
Step 1: Check If Inquirer Is Installed
First, verify if inquirer is in your project. Open your terminal and navigate to your project folder. Run this command:
npm list inquirer
If installed, you will see the version number. If not, you will see an error like missing: inquirer. This means you need to install it.
If you see the package listed but still get the error, it might be a version mismatch. Move to the next step.
Step 2: Install or Reinstall Inquirer
To fix the missing module, install inquirer locally in your project. Run this command:
npm install inquirer
This adds the package to your node_modules folder and updates package.json. If you already have it installed, reinstall to clear any corruption:
npm uninstall inquirer && npm install inquirer
After this, test your script again. The error should disappear.
Step 3: Check Your Node.js Version
Some versions of inquirer require a specific Node.js version. Check your Node.js version with:
node --version
If you have an older Node.js version, upgrade to the latest LTS version. You can use a version manager like nvm for this. After upgrading, reinstall inquirer and try again.
Step 4: Verify Your Require Statement
Make sure your code uses the correct require statement. The common way is:
const inquirer = require('inquirer');
If you are using ES modules, use import instead:
import inquirer from 'inquirer';
Also, check for typos. Sometimes a simple spelling mistake causes the error. Ensure the package name is exactly inquirer.
Step 5: Check Global vs Local Installation
If you installed inquirer globally, your script might not find it. Local installations are preferred for projects. To install locally, run:
npm install inquirer --save
If you need a global installation for CLI tools, install it with:
npm install -g inquirer
Then, ensure your script runs in the correct environment. For more guidance on similar issues, see our Fix Node.js Error: Cannot find module guide.
Example Code and Output
Here is a simple example using inquirer to ask for user input. This code runs without errors if the package is installed correctly.
// example.js
const inquirer = require('inquirer');
async function askName() {
const answers = await inquirer.prompt([
{
type: 'input',
name: 'username',
message: 'What is your name?'
}
]);
console.log(`Hello, ${answers.username}!`);
}
askName();
When you run this script, you should see output like:
? What is your name? John
Hello, John!
If you get the error, go back through the steps above. The issue is almost always a missing or corrupted package.
Prevent Future Errors
To avoid this error in the future, always install packages locally in your project. Use a package.json file to track dependencies. Run npm install after cloning a project to fetch all packages.
Also, use a version manager like nvm to keep Node.js consistent across projects. This prevents version conflicts.
Conclusion
The Cannot find module 'inquirer' error is easy to fix. Check if the package is installed. Reinstall it if needed. Verify your Node.js version and require statement. For more help with similar errors, refer to our Fix Node.js Error: Cannot find module article.
By following these steps, you can get your script running again quickly. Always keep your dependencies up to date and properly installed.