prettier / prettier-emacs

Minor mode to format JS code on file save
http://jlongster.com/A-Prettier-Formatter
372 stars 53 forks source link

"prettier errors: env: node: No such file or directory" #63

Open hew-wolff opened 4 years ago

hew-wolff commented 4 years ago

Running prettier-js gives the error above. I did some searching and reading, and found that the "env" error usually means something is missing from the Emacs exec-path, so I tried things like this in .emacs:

(add-to-list 'exec-path "/Users/hewwolff/.nvm/versions/node/v10.18.1/bin")

As far as I can tell, node and prettier are both available at that path, but I still get the error.

Environment:

$ prettier -v
1.19.1
$ system_profiler SPSoftwareDataType
Software:

    System Software Overview:

      System Version: macOS 10.15.3 (19D76)
      Kernel Version: Darwin 19.3.0
      Boot Volume: Macintosh HD
      Boot Mode: Normal
      Computer Name: Hew’s MacBook Pro
      User Name: Hew Wolff (hewwolff)
      Secure Virtual Memory: Enabled
      System Integrity Protection: Enabled
      Time since boot: 3 days 1:38

$ node -v
v10.18.1
petsgre commented 4 years ago

i get same error

itzikBraun commented 3 years ago

I found this issue in NVM repository. I tried sudo env node in the terminal and had the same error as I got in emacs, i.e env: node: No such file or directory.

I am not sure why emacs has the same behavior as running sudo, but it only happens when I start emacs from desktop. If I run emacs from command line (with or without GUI), prettierjs works as expected.

I hope it helps even if it doesn't solve the problem completely. Maybe a more in depth reading of that thread will lead you to the answer, I am satisfied with running it from command line.

LionyxML commented 2 years ago

I do have this problems with MacOS also.

It seems to be a broader issue then just prettier.

When I start Emacs from Applications or Spotlight, env outputs different then when loading from the terminal.

You can output your env in shell and then output the env from e-shell inside emacs. If they are different you have this "broader" problem.

When launching from command line, repeat this experiment and you'll see both will be the same values.

This guy here made a "fix" for MacOS. If you're not in MacOS, I am sure something can be done with xdg or the default X launcher: https://gist.github.com/d12frosted/18ed4b3b5d5267428a0da16da6d016b4

LionyxML commented 2 years ago

Also this did not fixed for me.

I usually run: $ Open /Application/Emacs.app

ishambhandari commented 2 years ago

Try copying your ~/.bashrc to ~/.bash_profile. And source ~/.bash_profile.

LionyxML commented 2 years ago

I found the solution to this problem by installing this beauty from MELPA: https://github.com/purcell/exec-path-from-shell

After install, justa add this anywhere in your .emacs file: (exec-path-from-shell-initialize)

And that's it. Now your shell path is available to GUI MacOS fired from from Desktop Applications, allowing you to run prettier, node, etc.