coc-prettier icon indicating copy to clipboard operation
coc-prettier copied to clipboard

Save handler can't find package

Open tbo opened this issue 2 years ago • 1 comments

I've encountered an issue in my development setup involving Prettier, the prettier-plugin-tailwindcss plugin, and a PNPM monorepo environment. Notably, when I save a file, the expected formatting by Prettier doesn't take place. While there's no immediate error message displayed on save, I unearthed an error in the logs when inspecting with :CocOpenLog.

Logs:

2023-09-16T13:04:14.668 INFO (pid:8252) [core-watchman] - watchman watching project: /Users/tbo/git/project
2023-09-16T13:04:17.447 ERROR (pid:8252) [core-documents] - Error on will save handler: Error: Cannot find package 'prettier-plugin-tailwindcss' imported from /Users/tbo/noop.js
    at new NodeError [90m(file:///Users/tbo/[39mgit/project/node_modules/[4m.pnpm[24m/[email protected]/node_modules/[4mprettier[24m/index.mjs:18797:5[90m)[39m
    at packageResolve [90m(file:///Users/tbo/[39mgit/project/node_modules/[4m.pnpm[24m/[email protected]/node_modules/[4mprettier[24m/index.mjs:19742:9[90m)[39m
    at moduleResolve [90m(file:///Users/tbo/[39mgit/project/node_modules/[4m.pnpm[24m/[email protected]/node_modules/[4mprettier[24m/index.mjs:19774:20[90m)[39m
    at defaultResolve [90m(file:///Users/tbo/[39mgit/project/node_modules/[4m.pnpm[24m/[email protected]/node_modules/[4mprettier[24m/index.mjs:19879:15[90m)[39m
    at resolve [90m(file:///Users/tbo/[39mgit/project/node_modules/[4m.pnpm[24m/[email protected]/node_modules/[4mprettier[24m/index.mjs:19897:12[90m)[39m
    at importFromFile [90m(file:///Users/tbo/[39mgit/project/node_modules/[4m.pnpm[24m/[email protected]/node_modules/[4mprettier[24m/index.mjs:19912:15[90m)[39m
    at importFromDirectory [90m(file:///Users/tbo/[39mgit/project/node_modules/[4m.pnpm[24m/[email protected]/node_modules/[4mprettier[24m/index.mjs:20181:10[90m)[39m
    at [90mfile:///Users/tbo/[39mgit/project/node_modules/[4m.pnpm[24m/[email protected]/node_modules/[4mprettier[24m/index.mjs:20198:12
    at async loadPlugin [90m(file:///Users/tbo/[39mgit/project/node_modules/[4m.pnpm[24m/[email protected]/node_modules/[4mprettier[24m/index.mjs:20203:28[90m)[39m
    at async Promise.all (index 0) {
  code: [32m'ERR_MODULE_NOT_FOUND'[39m
}

Running the Prettier CLI directly via the command ./node_modules/.bin/prettier ./src/ --write executes without any hitches, ensuring proper formatting. However, the in-editor save functionality seems to be at odds. A temporary relief can be achieved by restarting CoC using the :CocRestart command. After that, everything works as expected.

This behavior began roughly two weeks ago. I'm inclined to consider that it could be intertwined with recent modifications, potentially those related to the Prettier 3.0 upgrade.

tbo avatar Sep 16 '23 11:09 tbo

This is happening for me as well. In my case I am also using Prettier 3 and have the following .prettierrc.yml file:

# All of these are defaults except singleQuote and endOfLine, but we specify them
# for explicitness
endOfLine: auto
singleQuote: true
trailingComma: all
plugins: ['prettier-plugin-sort-json']

I am getting a similar error: Error resolve node module 'prettier-plugin-sort-json'.

mcmire avatar Aug 15 '25 19:08 mcmire