Hi,
Everything was working fine but then suddenly I began to receive the error message Cannot read property 'prettier' of undefined when trying to format the code. The only difference I remember is that I updated my VSCode extensions.
I uninstalled the extension, reload and the reinstalled again the extension but he problem remains.
I have VSCode 1.11.1 installed on Mac OSX 10.11.6 (El Capitan).
I've seen it, the fix is here #74
As a current workaround, be sure your package.json contains dependencies and devDependencies. They may be empty {}
Hi @CiGit,
Mi package.json has dependencies and devDependencies objects with many properties.

I've also checked the prettier package.json included with the extension and it's not empty either.

Can you also check in parent package.json if any?
I'm having the same problem after the update.
Also no package.json without dependencies and devDependencies?
on the path from / to your file ?
@CiGit the parent package.json also appears OK, with the dependencies properly declared (esbenp.prettier-vscode-0.13.0/package.json):

I was meaning in package.json located along the path
/
package.json
a/
package.json
b/
.....
workspace
package.json
dir/
fileToFormat.js
This are the place where it could occur.
@CiGit There only 1 package.json in my project tree is a CRA(create-react-app) and goes as follow:
/ProjectRoot
/node_modules
/src
myfileToFormat.js
package.json (My project. No empty deps objects)
the only additional package.json files are the ones related to the proper project dependencies but they're in the node_modules directory which is not along my src files path.
Is it more clear now?
I got this exact same problem after updating.
EDIT:
I got it to work by adding "prettier": "^1.1.10" to devDependencies and do npm install
I still don't know where it can come from. Is it possible for you to debug it? I won't ask your entire file system :smiling_imp:
Like @JesusIslam - things resolved for me when installing Prettier locally into the repo. So it seems like VSCode might not be checking for a globally installed copy and defaulting to that?
@jtulk #67 seems right, it needs to be explicitly installed now.
Indeed!
I installed prettier as devDependency and the problem was solved.
It would be excellent to add a note in the readme.md that prettier needs to be available as a dependency for the project or at least installed as a global (I didn't check if it works when prettier is installed as global module).
@mogarick it didn't work as a global for me at least.
Just published 0.13.1 with a patch that should correct this issue. At least what I could reproduce.
@esbenp I finally found out how to publish ... was really tough
@CiGit - Does the patch require a local install or will it work off a global install now? I'll be happy to do a PR to annotate the docs if it requires a local copy...
It loads prettier packed with the extension if there is no local install. It doesn't use your globally installed prettier.
PR welcome to update https://github.com/esbenp/prettier-vscode#prettier-resolution ;-)
I just hit this today VSCode Version 1.16.1, prettier-vscode 0.24.0 and had to install prettier locally to fix it (npm i -D prettier) it was working fine without that previously...
@tizmagik How was your setup before you installed prettier? Stack trace?
Where would the stacktrace be? All I saw was the Cannot read property 'prettier' of undefined message in the output tab
Damn, I also forgot some informations here. I meant debug it :-)
clone it, npm i, open it in vscode and F5 (Start debugging)
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I've seen it, the fix is here #74
As a current workaround, be sure your package.json contains
dependenciesanddevDependencies. They may be empty{}