radian-software / apheleia

🌷 Run code formatter on buffer contents without moving point, using RCS patches and dynamic programming.
MIT License
517 stars 73 forks source link

Failed to run apheleia-npx: exit status 1 (see buffer *apheleia-apheleia-npx-log*) #289

Open MoskitoHero opened 4 months ago

MoskitoHero commented 4 months ago

I am experiencing an issue with this package in my ruby on rails project.

I am using doom emacs - latest pinned version, which is 96a9805ecb75aac2adde7568d26b3e3b3ffc19af.

🐛 Whenever I save a file, I get this error message in the messages buffer: Failed to run apheleia-npx: exit status 1 (see buffer *apheleia-apheleia-npx-log*)

And this is what that buffer tells me:

$ apheleia-npx prettier --stdin-filepath /Users/cedricdelalande/dev/stockpro/stockpro-api/app/models/order/es_search.rb --plugin\=\@prettier/plugin-ruby --parser\=ruby

[error] Cannot find package '@prettier/plugin-ruby' imported from /Users/cedricdelalande/dev/stockpro/stockpro-api/noop.js

Command succeeded with exit code 1.

I have a node_modules directory, but I do not want to touch package.json as dependencies are a bit touchy on this project.

I did try to install @prettier, etc. locally, but when I did, what I got was another error:

apheleia-npx prettier --stdin-filepath /Users/cedricdelalande/dev/stockpro/stockpro-api/app/models/order/es_search.rb --plugin\=\@prettier/plugin-ruby --parser\=ruby

[error] /Users/cedricdelalande/dev/stockpro/stockpro-api/app/models/order/es_search.rb: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received null
[error]     at validateString (node:internal/validators:162:11)
[error]     at Object.dirname (node:path:1279:5)
[error]     at spawnServer (file:///Users/cedricdelalande/dev/stockpro/stockpro-api/node_modules/@prettier/plugin-ruby/src/plugin.js:79:24)
[error]     at async parse (file:///Users/cedricdelalande/dev/stockpro/stockpro-api/node_modules/@prettier/plugin-ruby/src/plugin.js:154:27)
[error]     at async parse4 (file:///Users/cedricdelalande/dev/stockpro/stockpro-api/node_modules/prettier/index.mjs:22117:11)
[error]     at async coreFormat (file:///Users/cedricdelalande/dev/stockpro/stockpro-api/node_modules/prettier/index.mjs:22607:7)
[error]     at async formatWithCursor (file:///Users/cedricdelalande/dev/stockpro/stockpro-api/node_modules/prettier/index.mjs:22809:14)
[error]     at async formatStdin (file:///Users/cedricdelalande/dev/stockpro/stockpro-api/node_modules/prettier/internal/cli.mjs:6587:23)
[error]     at async main (file:///Users/cedricdelalande/dev/stockpro/stockpro-api/node_modules/prettier/internal/cli.mjs:7077:5)
[error]     at async Module.run (file:///Users/cedricdelalande/dev/stockpro/stockpro-api/node_modules/prettier/internal/cli.mjs:7027:5)

Command succeeded with exit code 2.

I read through the README to see if I had overlooked some installation step, but I cannot see anything relevant...

inscapist commented 3 months ago

@MoskitoHero the second error is because you are missing a prettierrc config. Adding it to your project should help.

https://github.com/prettier/plugin-ruby

raxod502 commented 3 months ago

The first step to debugging Apheleia running a formatter is to run the formatter yourself. Once you figure out the correct command line to invoke the formatter, you can come back and configure Apheleia to use that - or propose a change to the default. But Apheleia has nothing to do with formatter installation or configuration, it just runs the configured command line.