prettier-vscode
prettier-vscode copied to clipboard
Cannot resolve config if `prettierPath` is defined
Summary
When using the prettier.prettierPath
setting in VS Code, the configuration file cannot be resolved and prettier will not format the current file when editor.formatOnSave
is set to true.
Github Repository to Reproduce Issue
I created a git repository, where the Error can be reproduced: https://github.com/leifmarcus/prettier-bug-prettierPath
Steps To Reproduce:
- Clone the linked repository
- Install all recommended extensions in vs code.
- Open the
Test.vue
file (or thetest.ts
file). - Save the file in VS Code
- See the error in the prettier console.
Expected result
Prettier should format the file without errors
Actual result
Error is thrown in the prettier console
Additional information
VS Code Version:
Version: 1.80.2
Commit: 2ccd690cbff1569e4a83d7c43d45101f817401dc
Date: 2023-07-27T20:57:59.134Z
Electron: 22.3.14
ElectronBuildId: 22695494
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 22.5.0
Prettier Extension Version: v10.1.0
OS and version: Mac OSVentura 13.4.1 ©
Prettier Log Output
["INFO" - 11:32:56] Formatting file:///Users/leifmarcus/_coding/prettier-bug-prettierPath/Test.vue
["ERROR" - 11:32:56] Error resolving prettier configuration for /Users/leifmarcus/_coding/prettier-bug-prettierPath/Test.vue
["ERROR" - 11:32:56] Invalid host defined options
TypeError: Invalid host defined options
at Object.<anonymous> (/Users/leifmarcus/_coding/prettier-bug-prettierPath/node_modules/prettier/index.cjs:600:23)
at Module.u._compile (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:1271)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1243:10)
at Module.load (node:internal/modules/cjs/loader:1058:32)
at Module._load (node:internal/modules/cjs/loader:893:12)
at Function.f._load (node:electron/js2c/asar_bundle:2:13330)
at Function.l._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:127:28070)
at Function.p._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:127:25404)
at Function.u._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:91:22191)
at Module.require (node:internal/modules/cjs/loader:1082:19)
at g (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:647)
at t.loadNodeModule (/Users/leifmarcus/.vscode/extensions/esbenp.prettier-vscode-10.1.0/dist/extension.js:1:2829)
at t.PrettierMainThreadInstance.import (/Users/leifmarcus/.vscode/extensions/esbenp.prettier-vscode-10.1.0/dist/extension.js:1:17760)
at t.ModuleResolver.getPrettierInstance (/Users/leifmarcus/.vscode/extensions/esbenp.prettier-vscode-10.1.0/dist/extension.js:1:5728)
at t.default.handleActiveTextEditorChanged (/Users/leifmarcus/.vscode/extensions/esbenp.prettier-vscode-10.1.0/dist/extension.js:1:10771)
at t.default.handleActiveTextEditorChangedSync (/Users/leifmarcus/.vscode/extensions/esbenp.prettier-vscode-10.1.0/dist/extension.js:1:10373)
at t.default.registerDisposables (/Users/leifmarcus/.vscode/extensions/esbenp.prettier-vscode-10.1.0/dist/extension.js:1:13531)
at /Users/leifmarcus/.vscode/extensions/esbenp.prettier-vscode-10.1.0/dist/extension.js:1:82528
After days of trying to figure out why Prettier would not work properly, this was great. Thanks for finding this.
Any thoughts on when a fix will be available?
I solved this error by specifying the prettier commonjs entrypoint instead of the folder I had before.
In .vscode/settings.json
i changed this
-"prettier.prettierPath": "./packages/compiler/node_modules/prettier",
+"prettier.prettierPath": "./packages/compiler/node_modules/prettier/index.cjs",
This feels like the extension should resolve it automatically but this seems to at least be a workaround for now.
@timotheeguerin thank you saved my day! works well
@timotheeguerin thanks, for me (using 2.2.0 because 3.0 is broken it seems?) I had to make it
-"prettier.prettierPath": "./packages/compiler/node_modules/prettier",
+"prettier.prettierPath": "./packages/compiler/node_modules/prettier/index.js",
// ^
Maybe duplicate of https://github.com/prettier/prettier-vscode/issues/3059?
I'm experiencing the same problem in one of my projects. I could solve it by appending index.cjs
to the path as described above.
Strange thing is, that in another project the configuration works without that addition.
I solved this error by specifying the prettier commonjs entrypoint instead of the folder I had before.
In
.vscode/settings.json
i changed this-"prettier.prettierPath": "./packages/compiler/node_modules/prettier", +"prettier.prettierPath": "./packages/compiler/node_modules/prettier/index.cjs",
This feels like the extension should resolve it automatically but this seems to at least be a workaround for now.
Is there any solution for Yarn with PnP?
After run yarn dlx @yarnpkg/sdks vscode
, my VSCode hangs forever with FormatOnSave
.
"prettier.prettierPath": ".yarn/sdks/prettier/index.js"
I solved this error by specifying the prettier commonjs entrypoint instead of the folder I had before. In
.vscode/settings.json
i changed this-"prettier.prettierPath": "./packages/compiler/node_modules/prettier", +"prettier.prettierPath": "./packages/compiler/node_modules/prettier/index.cjs",
This feels like the extension should resolve it automatically but this seems to at least be a workaround for now.
Is there any solution for Yarn with PnP? After run
yarn dlx @yarnpkg/sdks vscode
, my VSCode hangs forever withFormatOnSave
."prettier.prettierPath": ".yarn/sdks/prettier/index.js"
I downgraded prettier to version 2.x.x and then restarted VS Code. This fixed the hang issue for me.
I solved this error by specifying the prettier commonjs entrypoint instead of the folder I had before. In
.vscode/settings.json
i changed this-"prettier.prettierPath": "./packages/compiler/node_modules/prettier", +"prettier.prettierPath": "./packages/compiler/node_modules/prettier/index.cjs",
This feels like the extension should resolve it automatically but this seems to at least be a workaround for now.
Is there any solution for Yarn with PnP? After run
yarn dlx @yarnpkg/sdks vscode
, my VSCode hangs forever withFormatOnSave
."prettier.prettierPath": ".yarn/sdks/prettier/index.js"
Seems they fixed it in 3.0.3
!
I was investigating this issue as well, after upgrading to prettier 3.0.3 and adding
"prettier.prettierPath": ".yarn/sdks/prettier/index.js"
it started to work and the hanging for ever stopped.
I solved this error by specifying the prettier commonjs entrypoint instead of the folder I had before. In
.vscode/settings.json
i changed this-"prettier.prettierPath": "./packages/compiler/node_modules/prettier", +"prettier.prettierPath": "./packages/compiler/node_modules/prettier/index.cjs",
This feels like the extension should resolve it automatically but this seems to at least be a workaround for now.
Is there any solution for Yarn with PnP? After run
yarn dlx @yarnpkg/sdks vscode
, my VSCode hangs forever withFormatOnSave
."prettier.prettierPath": ".yarn/sdks/prettier/index.js"
Seems they fixed it in
3.0.3
!
Any chance to get this fixed for good as it is very annoying to have prettier extension broken when prettier is current 3.0.3 installed globally.
I don't have prettierPath
configured, but I keep getting this error after a while. Then I restart, am good for a while, then it comes back again. I keep restarting VS Code each time to fix it for a while.
- https://github.com/prettier/prettier-vscode/issues/3114
Thanks, that worked for me!
Thanks, worked for me!
This issue has been labeled as stale due to inactivity. Reply to keep this issue open.
This is still an issue for me, on 3.2.5.
Using prettier.config.js
Restarting VS Code solves the issue... until it comes back, every time.
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.