Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bug: conform is not discovering prettier plugins #515

Closed
1 task done
killtheliterate opened this issue Aug 7, 2024 · 3 comments
Closed
1 task done

bug: conform is not discovering prettier plugins #515

killtheliterate opened this issue Aug 7, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@killtheliterate
Copy link

killtheliterate commented Aug 7, 2024

Neovim version (nvim -v)

NVIM v0.10.1

Operating system/version

MacOS 14.5

Add the debug logs

  • I have set log_level = vim.log.levels.DEBUG and pasted the log contents below.

Log file

Log file: /Users/x/.local/state/nvim/conform.log
          
          16:57:07[ERROR] Formatter 'prettierd' error: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'prettier-plugin-tailwindcss' imported from /Users/x/repos/y/noop.js
          
          17:00:55[DEBUG] Running formatters on /Users/x/repos/y/src/App.tsx: { "prettierd" }
          17:00:55[INFO] Run prettierd on /Users/x/repos/y/src/App.tsx
          17:00:55[DEBUG] Run command: { "prettierd", "/Users/x/repos/y/src/App.tsx" }
          17:00:55[DEBUG] Run CWD: /Users/x/repos/y
          17:00:55[INFO] prettierd exited with code 1
          17:00:55[DEBUG] prettierd stdout: { "Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'prettier-plugin-tailwindcss' imported from /Users/x/repos/y/noop.js", "" }
          17:00:55[DEBUG] prettierd stderr: { "" }
          17:00:55[ERROR] Formatter 'prettierd' error: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'prettier-plugin-tailwindcss' imported from /Users/x/repos/y/noop.js

Describe the bug

Conform (I think) is having trouble discovering the prettier plugin included in the project. prettierd and prettier both try to find the plugin in noop.js

What is the severity of this bug?

tolerable (can work around it)

Steps To Reproduce

  1. Create a TypeScript project using npm
  2. Add prettier and prettier-plugin-tailwindcss
  3. Add a .prettierrc to the project, with { "plugins": ["prettier-plugin-tailwindcss"] }
  4. Configure conform for TypeScript: formatters_by_ft = { typescript = { 'prettierd', 'prettier', stop_after_first = true } }
  5. Create a TypeScript file, add some content, and attempt to format the file.

Expected Behavior

conform discovers prettier plugins, and applies them.

Minimal example file

import { useState } from "react"
import reactLogo from "./assets/react.svg"
import viteLogo from "/vite.svg"
import "./App.css"

function App() {
  const [count, setCount] = useState(0)

  return (
    <>
    
      <div className="bg-black mx-2 rounded">
        <a href="https://vitejs.dev" target="_blank">
          <img src={viteLogo} className="logo" alt="Vite logo" />
        </a>
        <a href="https://react.dev" target="_blank">
          <img src={reactLogo} className="logo react" alt="React logo" />
        </a>
      </div>
      <h1>Vite + React</h1>
      <div className="card">
        <button onClick={() => setCount((count) => count + 1)}>
          count is {count}
        </button>
        <p>
          Edit <code>src/App.tsx</code> and save to test HMR
        </p>
      </div>
      <p className="read-the-docs">
        Click on the Vite and React logos to learn more
      </p>
    </>
  )
}

export default App

Minimal init.lua

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
    "stevearc/conform.nvim",
    config = function()
      require("conform").setup({
        log_level = vim.log.levels.DEBUG,
        formatters_by_ft = { typescript = { 'prettierd', 'prettier', stop_after_first = true } }

      })
    end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Additional context

No response

@killtheliterate killtheliterate added the bug Something isn't working label Aug 7, 2024
@stevearc
Copy link
Owner

stevearc commented Aug 8, 2024

Can you follow the steps detailed in the debugging docs and come up with a prettier or prettierd invocation that works in your shell?

@stevearc stevearc added the question Further information is requested label Aug 8, 2024
@killtheliterate
Copy link
Author

prettier seems to be functioning as expected now. Seems to be a prettierd issue generally -> fsouza/prettierd#352

I did have success with prettierd restart, after installing prettierd globally, rather than the mason-tools install.

@Tushant
Copy link

Tushant commented Feb 3, 2025

the formatting is not working for me for JS and react based projects. It works for python based projects though.

Log file: /Users/username/.local/state/nvim/conform.log
          Require stack:
          - /Users/username/projects//my-project/mobile-my-project/node_modules/prettier-plugin-organize-imports/index.js
          
          2025-01-24 22:12:23[ERROR] Formatter 'prettierd' error: Error: Cannot find module 'prettier/parser-babel'
          Require stack:
          - /Users/username/projects//my-project/mobile-my-project/node_modules/prettier-plugin-organize-imports/index.js
          
          2025-01-24 22:12:48[ERROR] Formatter 'prettierd' error: Error: Cannot find module 'prettier/parser-babel'
          Require stack:
          - /Users/username/projects//my-project/mobile-my-project/node_modules/prettier-plugin-organize-imports/index.js
          
          2025-01-26 13:57:20[WARN] Formatter 'prettier' timeout
          2025-01-30 18:59:54[WARN] Formatter 'ruff_fix' timeout
          2025-01-31 19:54:51[WARN] Formatter 'prettierd' timeout
          2025-01-31 20:13:41[WARN] Formatter 'prettier' timeout
          2025-01-31 21:06:37[WARN] Formatter 'ruff_fix' timeout
          2025-02-01 05:54:14[WARN] Formatter 'prettier' timeout

Formatters for this buffer:
LSP: vtsls
prettierd ready (javascriptreact, json, graphql, javascript, typescriptreact) /Users/username/.local/share/nvim/mason/bin/prettierd

Other formatters:
ruff_fix ready (python) /Users/username/.local/share/nvim/mason/bin/ruff
ruff_format ready (python) /Users/username/.local/share/nvim/mason/bin/ruff
stylua ready (lua) /Users/username/.local/share/nvim/mason/bin/stylua

this is my conform setup

return {
  "stevearc/conform.nvim",
  event = { "BufReadPre", "BufNewFile" },
  config = function()
    local conform = require("conform")
    conform.setup({
      formatters_by_ft = {
        lua = { "stylua" },
        -- Conform will run multiple formatters sequentially
        python = { "ruff_fix", "ruff_format" },
        javascript = { "prettierd", stop_after_first = true },
        javascriptreact = { "prettierd", stop_after_first = true },
        typescriptreact = { "prettierd", stop_after_first = true },
        graphql = { "prettierd", stop_after_first = true },
        json = { "prettierd" },
      },
      format_on_save = {
        timeout_ms = 2000,
        lsp_format = "fallback",
      },
    })
    vim.keymap.set({ "n", "v" }, "<leader>mp", function()
      conform.format({
        lsp_fallback = true,
        async = false,
        timeout_ms = 2000,
      })
    end, { desc = "Format file or range(in visual mode)" })
  end,
}

formatting is not happening neither while saving nor running mp manually. I do have prettierd(0.26.1) installed globally. I have prettier installed in my project either.

  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@types/react": "^18.3.12",
    "babel-plugin-module-resolver": "^5.0.2",
    "prettier": "^3.4.2",
    "prettier-plugin-organize-imports": "^4.1.0"
  },

prettier.config.js (as per my project)

// prettier.config.js
module.exports = {
  arrowParens: 'avoid',
  printWidth: 120,
  tabWidth: 2,
  bracketSameLine: true,
  bracketSpacing: false,
  singleQuote: true,
  trailingComma: 'all',
  endOfLine: 'lf',
  // plugins: ['prettier-plugin-organize-imports'],
};

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants