prettier: Plugin autoload doesn't work for packages installed from GitHub and for Yarn PnP
Environments:
- Prettier Version: 2.0.5
 - Running Prettier via: CLI
 - Runtime: Node.js v14
 - Operating System: Windows
 
Steps to reproduce:
yarn add prettier/prettier @prettier/plugin-pug
Expected behavior:
Can format pug file with npx prettier test.pug
Actual behavior:
The CLI can’t load pug plugin automatically
Problem should be here, when install from github, ./node_modules/prettier maybe has own node_modules dir, so the autoLoadDir will be ./node_modules/prettier, not expected ./, so we are looking for ./node_modules/prettier/node_modules/@prettier/plugin-* not ./node_modules/@prettier/plugin-* (where the @prettier/plugin-pug is installed).
About this issue
- Original URL
 - State: closed
 - Created 4 years ago
 - Reactions: 6
 - Comments: 28 (24 by maintainers)
 
I think we have a wrong logic here right now https://github.com/prettier/prettier/blob/master/src/common/load-plugins.js.
Plugin(s) should be added to
package.json. For loading plugins we should userequire. Ideally we should not globnode_modules. Just note - Yarn PnP, doesn’t havenode_modules.Eslint looking at a configuration to find out which plugins are installed. But we 0CJS, so some plugins can’t be listed in the configuration.
package.jsononly one place to get list of plugins. But we should not forgetpackage.jsonalso may not exist, for example - Deno. In this case I think we should implement--pluginflag for CLI (like do Eslint).My vision:
package.jsonto get list of plugins (they should beprettier-plugin-*/@prettier/plugin-*).requireto load them.--pluginoption for nonpackage.jsonenvironments and for projects which doesn’t havepackage.json.Pros:
package.json.Cons:
--plugin-search-dir, so we should remove it and it is breaking change. But we can implement it without breaking change.prettier-plugin-nameindependencies, now we load a plugin, after this we can’t load. But we can keep globbing fromnode_modulesto avoid breaking change.These are my thoughts on this issue, I would like to hear other opinions.
Maybe we should take a look at Eslint logic. It is pretty well designed.
@kachkaev yeah i have, i actually made a bug report explicitly about the issue that the plugins get loaded but their file extensions dont get detected if load them using require() in the .prettierrc #13276
Ok so if I’m understanding correctly, the next major version of Prettier (3.0.0) will have the plugin autoload / automatic search feature removed, so that they will need to be specified always.
I like the idea to check listed plugins in
package.json, but I don’t like only load these plugins.If I want
@prettier/plugin-pug, I prefer add it to my@fisker/prettier-configinstead of adding to projectpackage.json.I prefer auto load
package.json.prettierrc(No support yet)@evilebottnawi It supports that. It accepts what
requireaccepts.