berry: [Bug] Prettier is unable to load plugins in PNP environment
- I’d be willing to implement a fix
Describe the bug
When using Prettier with plugins in a PNP environment, Prettier will not be able to find its plugins.
To Reproduce
We reproduced this on Discord with this repo:
https://github.com/oliversalzburg/prettier-plugin-pnp
Running yarn prettier src/index.ts
will not remove the unused import, for which the prettier-plugin-organize-imports
was installed.
Additional context
It was suggested that this is due to missing PNP functionality in the SDK wrapper. Enabling usePnpif
in https://github.com/yarnpkg/berry/blob/master/packages/yarnpkg-pnpify/sources/generateSdk.ts#L119 should be a valid solution to the problem.
This should probably be enabled through a CLI flag in yarn pnpify
to allow an adjusted SDK wrapper to be generated.
To actually fix the issue, I also need to supply the plugin search directory to Prettier manually. Otherwise it will search in a completely inapproriate location by default.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 25 (8 by maintainers)
Commits related to this issue
- fix(pnpify): Load prettier with in-memory node_modules enabled (#1905) * feat(pnpify): Optionally load PnPify in SDKs Using `--compat prettier,eslint`, the user can have the PnPify filesystem virt... — committed to yarnpkg/berry by oliversalzburg 4 years ago
- fix(pnpify): Load prettier with in-memory node_modules enabled (#1913) * fix(pnpify): Load prettier with in-memory node_modules enabled (#1905) * feat(pnpify): Optionally load PnPify in SDKs Us... — committed to yarnpkg/berry by larixer 4 years ago
I had this problem on VSCode, and after some debugging, figured out that when prettier is calling
require
(or something), it’s passing anoptions
object with apath
property pointing to VSCode’s installation directory. And I figured that dropping theoptions
object will fix the problem. So here is what I came up with for.yarn\sdks\prettier\index.js
:(Please note the
relPnpApiPath
variable. In my case, I had to change the extension from.js
to.cjs
. Change it according to your configuration.)I’ll see if we can release a new version of
@yarnpkg/pnpify
, in the meantime here is the updated versionWaiting for release !
It still does not work for me.
It hasn’t been released yet, but you can apply it manually by editing
.yarn\sdks\prettier\index.js
and changing it toI’ve tried replacing
.yarn\sdks\prettier\index.js
as prescribed, that didn’t do anything. Then I tried listing/requiring the plugins explicitly in the config, like here, to no avail, I get aQualified path resolution failed
error. The plugin I’m trying this with isprettier-plugin-tailwind
. Am I missing something?I’ve it installed as described in the docs (as dependency - not devDependency)!
My project uses workspaces and to be sure, I’ve installed it in the root and all sub packages.
@asfernandes After discussion we decided to enable pnpify runtime on a per-tool basis and not shift the decision to the users, because they don’t know the tradeoffs involved. For
prettier
we will always enable pnpify runtime starting from the next@yarnpkg/pnpify
version: https://github.com/yarnpkg/berry/pull/1913