Nick Chen
Nick Chen

Reputation: 105

Prettier installed globally but command not found

I was trying to learn CLI tools and following the steps on MDN.

And below is the problem I met.

$ npm install --global prettier
C:\Users\Nick\AppData\Roaming\npm\prettier -> 
C:\Users\Nick\AppData\Roaming\npm\node_modules\prettier\bin-prettier.js
+ [email protected]
added 1 package from 1 contributor in 0.718s

I installed Prettier globally, and seems it succeeded. But as I tried to run the command, it showed

$ prettier
C:\Users\Nick\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found

I found this solution from google Solution

And then I found that my path was different from his

$ npm bin -g
C:\Users\Nick\AppData\Roaming\npm

It seems my Node was installed for only one user? But I can't figure out what's the exact problem. Could anyone show me a way?

I am lost...

Upvotes: 10

Views: 31810

Answers (3)

Tal Avissar
Tal Avissar

Reputation: 10314

install with yarn solved the problem

yarn global add prettier

Upvotes: 1

Dheeraj Maheshwari
Dheeraj Maheshwari

Reputation: 417

It helped for me let's try:

npm install -g prettier

Upvotes: 23

kiranvj
kiranvj

Reputation: 34147

First check if Node is accessible for you.

node -v should show some version number

Regarding the command not found.

This happens in a Windows machine. You need to add the npm path in Environment variables path

The path value will be C:\Users\YOUR-USERNAME\AppData\Roaming\npm

  • Right click This PC
  • Properties Advanced system settings -> Advacnced tab -> Environment variables
  • Under User variables Click path, then click Edit Append the path value (sample I pasted above.)

Now exit all command prompt windows and try your commands

Upvotes: 4

Related Questions