admin管理员组文章数量:1410712
I’ve got a GitHub package for my Prettier config that I use across a bunch of my projects. The config uses a plugin, and when I install the package using pnpm, it puts the plugin inside the .pnpm folder in node_modules, but then Prettier throws an error saying it can’t find the plugin.
Weird thing is — when I install it with npm, everything works just fine.
Here’s what my Prettier config file looks like:
/**
* @see
* @type {import("prettier").Config}
*/
module.exports = {
tabWidth: 4,
semi: false,
singleQuote: true,
importOrder: [
'^react|^react-dom',
'<THIRD_PARTY_MODULES>',
'^@core/(.*)$',
'^@server/(.*)$',
'^@ui/(.*)$',
'^[./]',
'<TYPES>',
],
importOrderSortSpecifiers: true,
importOrderMergeDuplicateImports: true,
plugins: ['@ianvs/prettier-plugin-sort-imports'],
}
I’ve tried installing the plugin both as a dependency and a devDependency in the package, but no luck either way.
Any idea how to fix this?
I’ve got a GitHub package for my Prettier config that I use across a bunch of my projects. The config uses a plugin, and when I install the package using pnpm, it puts the plugin inside the .pnpm folder in node_modules, but then Prettier throws an error saying it can’t find the plugin.
Weird thing is — when I install it with npm, everything works just fine.
Here’s what my Prettier config file looks like:
/**
* @see https://prettier.io/docs/configuration
* @type {import("prettier").Config}
*/
module.exports = {
tabWidth: 4,
semi: false,
singleQuote: true,
importOrder: [
'^react|^react-dom',
'<THIRD_PARTY_MODULES>',
'^@core/(.*)$',
'^@server/(.*)$',
'^@ui/(.*)$',
'^[./]',
'<TYPES>',
],
importOrderSortSpecifiers: true,
importOrderMergeDuplicateImports: true,
plugins: ['@ianvs/prettier-plugin-sort-imports'],
}
I’ve tried installing the plugin both as a dependency and a devDependency in the package, but no luck either way.
Any idea how to fix this?
Share asked Mar 9 at 18:47 HamidrezaHamidreza 1,56513 silver badges20 bronze badges1 Answer
Reset to default 0The problem is that pnpm uses a strict link structure with the .pnpm
directory, and Prettier has problems resolving plugins like this. But when you install with npm, it creates a basic flat node_modules structure, which Prettier can navigate more easily.
I can think in two options for you:
Option 1:
Use pnpm's packageExtensions feature
Add this to your package.json:
"pnpm": {
"packageExtensions": {
"prettier": {
"dependencies": {
"@ianvs/prettier-plugin-sort-imports": "*"
}
}
}
}
This tells pnpm that Prettier depends on your import plugin
Or option 2:
Use:
shamefully-hoist=true
Modify your .npmrc
file to make pnpm's dependency resolution more compatible with Prettier. This will make pnpm hoist all dependencies to the root of node_modules, almost like npm, see if it works!!
本文标签:
版权声明:本文标题:node modules - Prettier plugin not resolved when using GitHub package with pnpm, but works with npm - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744863047a2629182.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论