I use yarn2 to install dependencies
repo is private
yarn installusual behaviour as it was on prior version of yarn
Error: Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have run npm install Attempted to load prettier from package.json
Sourse: Prettier - Code Formatter [extension]

VS Code Version: 1.41.1
Prettier Extension Version: 3.18.0
OS and version: MacOS 10.15.2 (19C57)
["ERROR" - 11:02:41 PM] Failed to load prettier from ''**Censored**
Cannot find module 'prettier' from '/Users/**Censored**/projects/**Censored**/**Censored**/package.json'
Error: Cannot find module 'prettier' from '/Users/**Censored**/projects/**Censored**/**Censored**/package.json'
at Function.e.exports [as sync] (/Users/**Censored**/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:319843)
at t.ModuleResolver.findPkg (/Users/**Censored**/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:246852)
at t.ModuleResolver.findPkg [as findPkgMem] (/Users/**Censored**/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:247210)
at t.ModuleResolver.requireLocalPkg (/Users/**Censored**/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:245330)
at t.ModuleResolver.getPrettierInstance (/Users/**Censored**/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:243969)
at t.LanguageResolver.getSupportLanguages (/Users/**Censored**/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:242420)
at t.LanguageResolver.allEnabledLanguages (/Users/**Censored**/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:242028)
at t.StatusBarService.toggleStatusBarItem (/Users/**Censored**/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:85577)
at /Users/**Censored**/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:85250
at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:641:245
at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
at f.$acceptDocumentsAndEditorsDelta (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:561:804)
at p._doInvokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:663:275)
at p._invokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:662:971)
at p._receiveRequest (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:661:639)
at p._receiveOneMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:660:468)
at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:658:691
at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
at _.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:189:274)
at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:820:285
at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
at _.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:189:274)
at t.PersistentProtocol._receiveMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:193:629)
at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:190:824
at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
at p.acceptChunk (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:186:737)
at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:186:89
at Socket.t (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:195:68)
at Socket.emit (events.js:200:13)
at addChunk (_stream_readable.js:294:12)
at readableAddChunk (_stream_readable.js:275:11)
at Socket.Readable.push (_stream_readable.js:210:10)
at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)
Any updates on this?
For now, you will have to set the prettier path. This is probably going to be a fairly large investment to fix due to how yarn2 has changed dependency resolution. I will try to look into it soon, but if somebody has expertise with yarn2 a PR would be welcome.
Thanks!
@arcanis Might be able to give pointers here
@ntotten the problem here is that even when setting the vscode setting ;
"prettier.prettierPath": ".vscode/pnpify/prettier/index.js"`
(As done automatically by following https://yarnpkg.com/advanced/editor-sdks )
It looks like the plugins still tries to load the version from package.json first instead of the explicitly configured path.
["INFO" - 7:15:59 PM] Formatting /Users/xxxx/Code/sterblue2/packages/algorithms/random/src/index.ts
["INFO" - 7:15:59 PM] Using ignore file (if present) at /Users/xxx/Code/sterblue2/.prettierignore
["ERROR" - 7:15:59 PM] Failed to load local module prettier.
["ERROR" - 7:15:59 PM] Cannot find module 'prettier' from '/Users/xxxx/Code/sterblue2/package.json'
Error: Cannot find module 'prettier' from '/Users/xxx/Code/sterblue2/package.json'
at Function.e.exports [as sync] (/Users/xxx/.vscode/extensions/esbenp.prettier-vscode-3.20.0/dist/extension.js:1:320528)
at t.ModuleResolver.findPkg (/Users/xxx/.vscode/extensions/esbenp.prettier-vscode-3.20.0/dist/extension.js:1:247279)
at t.ModuleResolver.findPkg (/Users/xxx/.vscode/extensions/esbenp.prettier-vscode-3.20.0/dist/extension.js:1:247381)
at t.ModuleResolver.findPkg [as findPkgMem] (/Users/xxxx/.vscode/extensions/esbenp.prettier-vscode-3.20.0/dist/extension.js:1:247637)
at t.ModuleResolver.requireLocalPkg (/Users/xxxx/.vscode/extensions/esbenp.prettier-vscode-3.20.0/dist/extension.js:1:245697)
at t.ModuleResolver.getPrettierInstance (/Users/xxxx/.vscode/extensions/esbenp.prettier-vscode-3.20.0/dist/extension.js:1:244301)
at t.default.<anonymous> (/Users/xxxx/.vscode/extensions/esbenp.prettier-vscode-3.20.0/dist/extension.js:1:348961)
at Generator.next (<anonymous>)
at s (/Users/xxxxx/.vscode/extensions/esbenp.prettier-vscode-3.20.0/dist/extension.js:1:345019)
["INFO" - 7:15:59 PM] Using bundled version of prettier.
["INFO" - 7:15:59 PM] File Info:
{
"ignored": false,
"inferredParser": "typescript"
}
["INFO" - 7:15:59 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 7:15:59 PM] Prettier Options:
{
"filepath": "/Users/xxxx/xxx/index.ts",
"parser": "typescript",
"useTabs": false,
"tabWidth": 2,
"printWidth": 80,
"semi": true,
"singleQuote": false,
"jsxSingleQuote": false,
"trailingComma": "none",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "avoid",
"htmlWhitespaceSensitivity": "css",
"endOfLine": "lf"
}
["INFO" - 7:15:59 PM] Formatting completed in 40.413031ms.
I _think_ the problem is that fileName is not passed to getConfig() here https://github.com/prettier/prettier-vscode/blob/master/src/ModuleResolver.ts#L91 so it always uses the workspace config, and not the project-local settings.
That is supported by the fact that if you set prettier.prettierPath at the Workspace level, it all seems to work fine. That's also a workaround, I think.
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
@ntotten the problem here is that even when setting the vscode setting ;
(As done automatically by following https://yarnpkg.com/advanced/editor-sdks )
It looks like the plugins still tries to load the version from
package.jsonfirst instead of the explicitly configured path.