Global plugins not being found
Hi, currently trying to use prettier-plugin-style-order and prettier-plugin-tailwindcss (both installed globally via npm), currently using neovim and null-ls to run prettierd.
local config = require("user.lsp.null-ls.formatting")
local formatting = null_ls.builtins.formatting
local sources = {
formatting.prettierd.with({
env = {
PRETTIERD_DEFAULT_CONFIG = vim.fn.expand("$HOME/.config/nvim/.prettierrc.json"),
},
}),
}
null_ls.setup({
sources = sources,
debounce = 200,
autostart = true,
debug = true,
on_attach = function(client, bufnr)
config.setup(client, bufnr)
end,
})
This is the prettier config
{
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "auto",
"printWidth": 80,
"semi": true,
"tabWidth": 2,
"bracketSameLine": true,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxSingleQuote": false,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false,
"configPrecedence": "prefer-file",
"plugins": ["prettier-plugin-style-order", "prettier-plugin-tailwindcss"]
}
and the error log
[TRACE qua 25 mai 2022 20:35:50] .../site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:121: received LSP request for method textDocument/formatting
[TRACE qua 25 mai 2022 20:35:50] ...ack/packer/start/null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_FORMATTING
[DEBUG qua 25 mai 2022 20:35:50] ...rt/null-ls.nvim/lua/null-ls/helpers/command_resolver.lua:35: attempting to find local executable node_modules/.bin/prettierd
[DEBUG qua 25 mai 2022 20:35:50] ...rt/null-ls.nvim/lua/null-ls/helpers/command_resolver.lua:41: Unable to resolve command [node_modules/.bin/prettierd], skipping further lookups
[DEBUG qua 25 mai 2022 20:35:50] ...t/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:286: Using dynamic command for [prettierd], got: "prettierd"
[DEBUG qua 25 mai 2022 20:35:50] ...t/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:346: spawning command "prettierd" at /home/todomir with args { "/home/todomir/dev/react/testing-fe/src/index.css" }
[TRACE qua 25 mai 2022 20:35:50] ...t/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:217: error output: Error: Cannot find module 'prettier-plugin-style-order'
Require stack:
- /home/todomir/.nvm/versions/node/v18.0.0/lib/node_modules/@fsouza/prettierd/node_modules/prettier/index.js
- /home/todomir/.nvm/versions/node/v18.0.0/lib/node_modules/@fsouza/prettierd/dist/service.js
- /home/todomir/.nvm/versions/node/v18.0.0/lib/node_modules/@fsouza/prettierd/node_modules/core_d/lib/server.js
- /home/todomir/.nvm/versions/node/v18.0.0/lib/node_modules/@fsouza/prettierd/node_modules/core_d/lib/daemon.js
[TRACE qua 25 mai 2022 20:35:50] ...t/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:218: output: nil
[TRACE qua 25 mai 2022 20:35:50] ...t/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:222: ignoring stderr due to generator options
[TRACE qua 25 mai 2022 20:35:50] .../site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:146: received LSP notification for method textDocument/didSave
[TRACE qua 25 mai 2022 20:35:50] ...ack/packer/start/null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS_ON_SAVE
[DEBUG qua 25 mai 2022 20:35:50] ...ack/packer/start/null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
Created a simpler reproducer:
#!/usr/bin/env bash
set -euo pipefail
npm i -g @fsouza/prettierd prettier-plugin-style-order
cat >/tmp/prettierc.json <<EOF
{
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "auto",
"printWidth": 80,
"semi": true,
"tabWidth": 2,
"bracketSameLine": true,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxSingleQuote": false,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false,
"configPrecedence": "prefer-file",
"plugins": ["prettier-plugin-style-order"]
}
EOF
env PRETTIERD_DEFAULT_CONFIG=/tmp/prettierc.json prettierd file.css <<EOF
body {
margin: 0;
}
EOF
Probably need to figure out the right parameters to make prettier discover global plugins. Will try to look into this some time next week.
Any movement on this one? Also getting this with plugins installed globally by yarn
.prettierrc
{
"plugins": ["prettier-plugin-go-tepmlate"]
}
Error: Cannot find module 'prettier-plugin-go-tepmlate'
Require stack:
- /Users/dev/.config/yarn/global/node_modules/prettier/index.js
- /Users/dev/.config/yarn/global/node_modules/@fsouza/prettierd/dist/service.js
- /Users/dev/.config/yarn/global/node_modules/core_d/lib/server.js
- /Users/dev/.config/yarn/global/node_modules/core_d/lib/daemon.js
@laughingman-hass thanks for commenting. There aren't any updates, but perhaps you're running into a different issue? Do you have a typo in tepmlate (instead of template)?
doh! good catch. had attempted it number of times before I thought I'd log it here. With the typo corrected it still provides the same error.
doh! good catch. had attempted it number of times before I thought I'd log it here. With the typo corrected it still provides the same error.
Thanks for confirming. I still haven't had a chance to look into this unfortunately
Any updates on this issue?
I can also see the same problem with plugins and prettierd:
[TRACE Tue Jun 20 12:24:27 2023] /Users/guga/.local/share/nvim/lazy/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:205: error output: Error: Cannot find module 'prettier-plugin-jsdoc'
Require stack:
- /Users/guga/Projects/joinflux/flux/packages/api-service/node_modules/prettier/index.js
- /Users/guga/.local/share/nvim/mason/packages/prettierd/node_modules/@fsouza/prettierd/dist/service.js
- /Users/guga/.local/share/nvim/mason/packages/prettierd/node_modules/@fsouza/prettierd/node_modules/core_d/lib/server.js
- /Users/guga/.local/share/nvim/mason/packages/prettierd/node_modules/@fsouza/prettierd/node_modules/core_d/lib/daemon.js
I too have come upon this problem and as I workaround I installed prettier globally and from Neovim i just run :!prettier --write "%"(created a keybinding for it) which is able to find the modules. Obviously, global prettier is able to find the modules from terminal as well when running the aforementioned command.