prettier-vscode: failed to load prettier from package.json

Summary

I receive an error when I open package.json file from VS Code

Steps To Reproduce:

  1. Open package.json with Prettier extension enabled
  2. Add these to settings.json:
"prettier.configPath": "/home/v1rtl/.prettierrc.yml",
"editor.defaultFormatter": "esbenp.prettier-vscode",

and create ~/.prettierrc.yml:

printWidth: 80
semi: false
singleQuote: true
useTabs: false

Expected result

I would open package.json with no errors

Actual result

It dropped this error:

Failed to load module. Attempted to load prettier from package.json.

Also in logs I saw this:

[INFO - 1:36:27 PM] Failed to load prettier from .

Additional information

VS Code Version: 1.40.0

Prettier & Prettier Plugin Version: 3.6.0

OS and version: Manjaro, Linux 4.19.84

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 17
  • Comments: 37 (15 by maintainers)

Most upvoted comments

The Failed to load module. Attempted to load prettier from package.json. error notification started after updating to VS Code to version 1.40.1.

For now, you can solve it by setting Prettier Path in your VS Code Settings.


https://stackoverflow.com/questions/58866847/in-vs-code-im-getting-this-error-failed-to-load-module-attempted-to-load-pr/58934707#58934707

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)

There seem to be a few different issues going on here.

  1. Prettier must be included in the package.json. Not just installed in the node_modules, but listed in the package.json. This is something I may change later, but that is the behavior now.

  2. In one of the logs provided I am seeing this error [ERROR - 8:10:32 AM] Outdated version of prettier installed. Falling back to bundled version of prettier. You need to make sure you are using prettier version 1.13 or above otherwise it will fallback to the bundled prettier.

  3. Global modules aren’t supported yet and never have been. This is also something we might change, but its not supported. As others have noted, you can make them work by setting the path to the global module in the Prettier Path setting.

@tunjioye Just want to point out the obvious - installing globally is very much a workaround. I’m always trying to minimize any kind of global installs on a dev machine to the bare minimum. Prettier is a big no-no to install globally for me. A plugin like this needs to be able to use the prettier version from the module at hand.

@ntotten I mean yarn global add prettier works but brew install prettier doesn’t work.

I both enabled prettierPath config correctly.

Can we fallback to global installed prettier bin instead if prettier not found from package.json?