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:
- Open package.json with Prettier extension enabled
- 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)
The
Failed to load module. Attempted to load prettier from package.json.
error notification started after updating to VS Code to version1.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
2. Search & Use the
Prettier Path
Extension Settings in your VS Code Settings// You can navigate to VS Code
Settings > Extensions > Prettier
for all Prettier Extension Settings3. 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.
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.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.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 butbrew install prettier
doesn’t work.I both enabled
prettierPath
config correctly.Can we fallback to global installed
prettier
bin instead ifprettier not found from package.json
?