-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
question: How to execute prettier with yarn? #323
Comments
When you run prettier with yarn, it should just be looking for the executable under
and the definition of that utility function conform.nvim/lua/conform/util.lua Lines 3 to 8 in 0a530b3
You will want to have formatters_by_ft = {
typescript = { 'prettier' },
typescriptreact = { 'prettier' },
}, If the |
I think this might be related to yarn plug and play (https://yarnpkg.com/features/pnp), which
I ran into some issues using yarn pnp when working with another project a couple of months ago, and was able to opt out of plug and play on the project level with My understanding of this issue is not that good, but for what it's worth, I'd like to make some recommendations: A workaroundLooks like someone was able to opt out of yarn pnp for prettier specifically using a command on their system only: yarnpkg/berry#5576 My guess is that you would also have to do this for all the prettier plugins that your project uses, but I have not tried this option myself. A long term fixTo get the benefits of yarn pnp for all users of conform.nvim automatically, I think yarn's editor sdks would be the correct way to do it (https://yarnpkg.com/getting-started/editor-sdks). It does mention neovim on the page, but I have to admit I don't understand this very well. |
@mikavilpas I use Yarn v4, but with linker node_modules. I don't use PnP. @stevearc I have
I think this may be related to Volta. For all my projects I install and pin Yarn versions with Volta. |
I see, it looks like the same setup that is working for me (namely, yarn 4 without pnp + conform.nvim). You could try ruling out Volta by using a project without it. Maybe you already have a project like this, but if not, you can clone https://github.com/GregRos/parjs/ and try it there. |
I found the problem. I've installed the prettier as a dev dependency using package.json. But I have the following directory/file setup in my node_modules.
Now, when I try to run But I don't know how to fix it. This You can tell me how to run |
Ok. It works with Parjs. It works with two other TS projects of mine. I guess the problem is with one specific project. The problem is not with the Conform plugin. I confirm. Thank you so much for your help! |
Thanks for the information. I have two projects that one is using Yarn PnP and the other is using npm. Running globally installed version of prettier doesn't work with locally installed prettier-plugin-tailwindcss. I ended up making this configuration for myself. It might be useful someone who have to use yarn pnp. https://gist.github.com/crierr/322ea6711df7614a000cb3f3be87bf93 -- If prettier is installed with Yarn PnP, run below command to generate bin-prettier.js.
-- `yarn dlx @yarnpkg/sdks base`
-- @see https://yarnpkg.com/getting-started/editor-sdks
local util = require("conform.util")
local fs = require("conform.fs")
return {
"stevearc/conform.nvim",
opts = {
formatters = {
prettier = {
command = function(self, bufnr)
local cmd = util.find_executable({ ".yarn/sdks/prettier/bin-prettier.js" }, "")(self, bufnr)
if cmd ~= "" then
return cmd
end
-- return type of util.from_node_modules is fun(self: conform.FormatterConfig, ctx: conform.Context): string
---@diagnostic disable-next-line
return util.from_node_modules(fs.is_windows and "prettier.cmd" or "prettier")(self, bufnr)
end,
},
},
},
} |
this solved my problem thanks!! |
Neovim version (nvim -v)
0.9.5
Operating system/version
MacOS 14.4
Add the debug logs
log_level = vim.log.levels.DEBUG
and pasted the log contents below.Log file
[WARN] No formatters found for file.tsx
Describe the bug
Hello there,
I am trying everything but cannot make
prettier
be executed byyarn
. I don't have prettier globally installed and I don't want to. Having a config like this:fails to find
prettier
and logs this warning:So, I am trying all possible combinations following the readme, but nothing seems to work. Here are my experiments, but there were more :)
With this config nothing seems to happen.
Help! How to invoke prettier with yarn?
Thanks.
What is the severity of this bug?
blocking (cannot use plugin)
Steps To Reproduce
Expected Behavior
The file is properly formatted using the prettier from the project.
Minimal example file
Minimal init.lua
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: