Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In VS Code, I'm getting this error, 'Failed to load module. Attempted to load prettier from package.json'

When I'm using VS Code and open up a project, I get this notification in the bottom right corner:

Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have runnpm installAttempted to load prettier from package.json.

Source: Prettier Code Format (Extension)

Running npm install doesn't resolve this. Anyone have any idea why that is or what I can do to fix it?

like image 877
ghostagent151 Avatar asked Nov 14 '19 21:11

ghostagent151


People also ask

How do I fix prettier errors in VS Code?

Open the terminal in your project root folder and install eslint as a dev dependency. We also need to enable the eslint and prettier extension for the VSCode. So visit the extensions section of VSCode (ctrl + shift + x) and search for Eslint and Prettier — Code formatter and install it.


2 Answers

This is a solution that worked for me

1. Install Prettier Globally via npm if you have never installed it globally

npm i prettier -g 

2. Search & Use the Prettier Path Extension Settings in your VS Code Settings

enter image description here

// You can navigate to VS Code Settings > Extensions > Prettier for all Prettier Extension Settings

3. Update the Prettier Path to your globally installed Prettier.

For Example

/usr/local/lib/node_modules/prettier (Mac OS)

\AppData\Roaming\npm\node_modules\prettier (Windows)

like image 76
Tunji Oyeniran Avatar answered Sep 22 '22 14:09

Tunji Oyeniran


When setting up Prettier it is important to configure it per-project. Not every project uses the same code style, thus it is important to respect the style of whatever project you are currently working in.

The demo repo bahmutov/prettier-config-example has two subfolders, each with its distinct code style, enforced by Prettier. In reality, each of your repos will have its style; I am using subfolders in order to keep the example simple.

npm install --save-dev --save-exact prettier

like image 21
Shanwaz Ghulam Avatar answered Sep 19 '22 14:09

Shanwaz Ghulam