Closed Lukewh closed 4 years ago
Hi- Yes, as described in the installation instructions, you’re responsible for making sure that node
is on exec-path
, unless you’re using nvm.
I don’t think this package should contain some elaborate detection logic. Other packages (say, magit) don’t either.
Have you considered using exec-path-from-shell?
Perhaps we could improve the error message here.
Ah, wait— it can find node, just not prettier. That’s odd. I’ll try reproducing this.
I thought it might be a snap confinement issue, but both Emacs and node are classically confined (access to entire system)
Ok, so far I've found that the following command returns the empty string in your setup (ie. Ubuntu 18 with Node installed via snap -- I've been following your repro instructions to the letter):
node --eval='process.stdout.write(require("child_process").execSync("npm root -g", { encoding: "utf-8" }))'
... while the same command (npm root -g
) prints the expected result when run directly in the shell, namely /usr/local/lib/node_modules
.
On MacOS Catalina as well as another copy of Ubuntu 18 that I have running (but without using snap) there is no difference between running npm directly vs running it from Node.
In addition, running the following command (in a directory that doesn't have prettier
installed locally) will throw Error: Cannot find module 'prettier'
:
node --eval='require("prettier")'
In short, it appears that installing node
via snap results in a broken installation, or more precisely, one that doesn't know how to access packages installed via npm install -g
.
Can you observe the same in your system?
Yeah, I can confirm this to be the case - I think it's out of scope of this project to fix so closing this issue :)! Thanks for your help! Sorry for the noise.
It's probably worth noting that simply setting (setenv "NODE_PATH" "/usr/local/lib/node_modules")
at the beginning of my init file remedied the situation :+1:
No worries... ah, good to know. I might start a little "troubleshooting" section with it.
I guess one suggestion, after thinking about it, would be to make the error more descriptive with maybe a link to the troubleshooting section you mentioned? Just a thought 😊. Thanks for the hard work on the package, either way!
Describe the bug Whenever I try to run prettier on save or directly I get the above error.
Link to
M-x prettier-info
output Link.which node: /snap/bin/node which prettier: /usr/local/bin/prettier npm root -g: /usr/local/lib/node_modules ls /usr/local/lib/node_modules/prettier:
To Reproduce
Expected behavior Prettier to find the global prettier
Additional context Add any other context about the problem here.