You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Globally installed prettier with no workspace root package.json fails to resolve correct prettier config. We're using Rush which has a specific way of handling prettier config, see https://rushjs.io/pages/maintainer/enabling_prettier/. Generally, this works fine, but for one of our users, they were unable to use this VSCode extension due to Invalid prettier configuration file detected. errors everytime they saved the file. After debugging, we discovered that they had prettier installed globally and this extension was attempting to use that version instead of the workspace one. I believe this is happening because this function doesn't stop at the workspace root and continues to resolve up, despite the resolveGlobalModules flag not being set.
Github Repository to Reproduce Issue
Since this is an interaction between global and local modules, will add steps below.
Steps To Reproduce:
(these will not replicate the exact same error, but I believe they indicate the same root cause)
Install VSCode prettier extension.
Ensure resolve global modules is unchecked in the prettier settings.
Create a package.json at ~/package.json.
Add the following to that file, {"dependencies": {"prettier": "2.2.3"}}. The file just needs to exist, the version doesn't matter.
Restart VSCode.
Save a file.
Expected result
Continued to the use the workspace version for prettier.
Actual result
["INFO" - 11:30:15 AM] Formatting file:///Users/aramis.sennyey/Projects/my-project/.prettierrc.js
["INFO" - 11:30:15 AM] Attempted to determine module path from /Users/aramis.sennyey
["ERROR" - 11:30:15 AM] Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have run `npm install`
["ERROR" - 11:30:15 AM] Cannot find module 'prettier' from '/Users/aramis.sennyey'
["INFO" - 11:30:15 AM] Formatting file:///Users/aramis.sennyey/Projects/my-project/.prettierrc.js
["INFO" - 11:30:15 AM] Attempted to determine module path from /Users/aramis.sennyey
["ERROR" - 11:30:15 AM] Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have run `npm install`
["ERROR" - 11:30:15 AM] Cannot find module 'prettier' from '/Users/aramis.sennyey'
Error: Cannot find module 'prettier' from '/Users/aramis.sennyey'
at Function.e.exports [as sync] (/Users/aramis.sennyey/.vscode/extensions/esbenp.prettier-vscode-10.4.0/dist/extension.js:1:41190)
at t.ModuleResolver.findPkg (/Users/aramis.sennyey/.vscode/extensions/esbenp.prettier-vscode-10.4.0/dist/extension.js:1:8482)
at t.ModuleResolver.getPrettierInstance (/Users/aramis.sennyey/.vscode/extensions/esbenp.prettier-vscode-10.4.0/dist/extension.js:1:4633)
at t.ModuleResolver.getResolvedConfig (/Users/aramis.sennyey/.vscode/extensions/esbenp.prettier-vscode-10.4.0/dist/extension.js:1:7691)
at t.default.format (/Users/aramis.sennyey/.vscode/extensions/esbenp.prettier-vscode-10.4.0/dist/extension.js:1:14793)
at t.PrettierEditProvider.provideEdits (/Users/aramis.sennyey/.vscode/extensions/esbenp.prettier-vscode-10.4.0/dist/extension.js:1:12887)
at t.PrettierEditProvider.provideDocumentFormattingEdits (/Users/aramis.sennyey/.vscode/extensions/esbenp.prettier-vscode-10.4.0/dist/extension.js:1:9117)
at V.provideDocumentFormattingEdits (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:154:108134)
at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:154:137096
at Pe.s (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:154:131471)
at Pe.$provideDocumentFormattingEdits (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:154:137083)
at S (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:151:5986)
at S.Q (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:151:5752)
at S.M (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:151:4739)
at S.L (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:151:3605)
at n.value (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:151:2297)
at r.B (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:83:737)
at r.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:83:954)
at o.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:108:14502)
at n.value (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:177:8639)
at r.B (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:83:737)
at r.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:83:954)
at o.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:108:14502)
at MessagePortMain.<anonymous> (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:177:6765)
at MessagePortMain.emit (node:events:514:28)
at Object.MessagePortMain._internalPort.emit (node:electron/js2c/utility_init:2:2285)
["INFO" - 11:30:15 AM] Using config file at /Users/aramis.sennyey/Projects/myproject/.prettierrc.js
The text was updated successfully, but these errors were encountered:
This is definitely happening to me as well, I have "devDependencies": { "prettier": "3.3.3" } in my package.json, but in prettier plugin log, I see:
PrettierInstance:
{
"modulePath": "<project path>/node_modules/prettier/index.cjs", // reference to locally installed prettier v3.3.3
"messageResolvers": {},
"version": "3.2.4" // I thought that this is a globally installed version, but it is not, and it is not the version of above prettier module?
}
EDIT: It's even weirder, according to the below script, I have no 3.2.4 prettier installed. Now I am very confused.
find ${HOME} -type d -name "node_modules" -maxdepth 5 -exec sh -c '
find "$1" -maxdepth 1 -type d -name "prettier" -print0 |
while IFS= read -r -d "" dir; do
echo "$dir"
if [ -f "$dir/package.json" ]; then
jq -r ".version // \"Version not found\"" "$dir/package.json"
else
echo "No package.json found"
fi
echo
done
' sh {} \;
Hmm, I had Prettier Monkey C extension installed. I tried completely uninstalling prettier plugin from VS code and installing it again, and as Prettier Monkey C is dependent on Prettier, I had to uninstall it too.
Removing both and installing back just Prettier (11.0.0 0 just like before the uninstall) seems to fix it - in the logs I now see 3.3.3 used.
Absolutely not sure what was happening, as the monkey c plugin was using different version:
Summary
Globally installed prettier with no workspace root
package.json
fails to resolve correct prettier config. We're using Rush which has a specific way of handling prettier config, see https://rushjs.io/pages/maintainer/enabling_prettier/. Generally, this works fine, but for one of our users, they were unable to use this VSCode extension due toInvalid prettier configuration file detected.
errors everytime they saved the file. After debugging, we discovered that they had prettier installed globally and this extension was attempting to use that version instead of the workspace one. I believe this is happening because this function doesn't stop at the workspace root and continues to resolve up, despite theresolveGlobalModules
flag not being set.Github Repository to Reproduce Issue
Since this is an interaction between global and local modules, will add steps below.
Steps To Reproduce:
(these will not replicate the exact same error, but I believe they indicate the same root cause)
resolve global modules
is unchecked in the prettier settings.package.json
at~/package.json
.{"dependencies": {"prettier": "2.2.3"}}
. The file just needs to exist, the version doesn't matter.Expected result
Continued to the use the workspace version for prettier.
Actual result
Additional information
Feel free to attach a screenshot.
VS Code Version:
Prettier Extension Version: v10.4.0
OS and version: MacOS
Prettier Log Output
The text was updated successfully, but these errors were encountered: