Cannot find module 'prettier' error [Solved]
The “Cannot find module ‘prettier’” error occurs due to one of the following reasons:
-
The
prettiermodule is not installed in the correct project directory. -
Using the module without installing it in the project.
-
Installed the moudle in a global context and trying to access in project local context.
To solve the error “Cannot find module ‘prettier’”, open the project root folder in your terminal and run the following command to install the prettier module.
npm install --save-dev prettierFor yarn:
yarn add --dev prettierIf you’re still facing the error, then follow the below steps to resolve it.
- Remove the
node_modulesfolder andpackage-lock.jsonfile, inside your project root directory by using the below command.
rm-rf node_modules package-lock.jsonor you can remove it manually by right-clicking on it and select the delete option.
- Clear the npm cache.
npm clean cache --force- Re-install the node modules again by running the
npm installcommand.
Verify now if you’ve installed it correctly or not by opening the package.json file and check for prettier module in the devDependencies object.
{
"devDependencies": {
"prettier": "^2.7.1",
}
}Conclusion
To solve the can’t find module prettier error, install the prettier module in your project directory by running the npm install --save-dev prettier command and restart your development server.
For yarn use the following command:
yarn add --dev prettier

