Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly re-configure JSPrettier after an update with a breaking change?

I am trying to make Jsprettier work in Sublime, but the formats I set up can't be applied, because I keep getting an error when I want to save a document (jsprettier: format failed). When I open the console to see what the error is it says: The system cannot find the path specified. (CR).

The settings in the user settings tab of jsprettier are the following:

{
    "prettier_cli_path": "/c/Users/Adri/AppData/Roaming/npm/prettier",
    "node_path": "/c/Program Files/nodejs/node",
    "auto_format_on_save": true,
    "prettier_options": {
        "printWidth": 120,
        "tabWidth": 2,
        "singleQuote": true,
        "trailingComma": "none",
        "bracketSpacing": true,
        "jsxBracketSameLine": false,
        "parser": "flow",
        "semi": true,
        "tabs": false
    }
}

Thank you

like image 564
Amogu Avatar asked Sep 13 '17 07:09

Amogu


3 Answers

tested on: Sublime Text 3.2.2, MacBook Pro

  • Install Js​Prettier globally using npm:
    npm install --global prettier
  • Install JsPrettier from Package Control by:
    Sublime Text-->Preferences-->Package Control-->type and enter: Install Package-->type and enter: JsPrettier
  • restart Sublime Text
like image 134
Eden Sharvit Avatar answered Nov 02 '22 11:11

Eden Sharvit


In your terminal run the following:

  1. which node

  2. which prettier

Copy the result of the output for each step and in SublimeText3 proceed to:

  • Preferences --> PackageSettings --> JsPrettier --> Settings-User

In the user settings build your file as such:

{   
    "prettier_cli_path": "output from terminal here",
    "node_path": "output from terminal here",
    "auto_format_on_save": true,
}

I found that when JsPrettier updates it erased these settings on me and needed to re-enter them...

Hope that helps.

like image 10
lopezdp Avatar answered Nov 02 '22 13:11

lopezdp


In case this helps anyone:

While this installed easily on one computer, I struggled with it on a second one.

After being required to set the node and prettier_cli path, I got node errors.

What worked in the end was setting the prettier_cli_path to prettier.js within the prettier node_modules directory as such:

C:/Users/Me/AppData/Roaming/npm/node_modules/prettier/bin-prettier.js

like image 2
yak Avatar answered Nov 02 '22 11:11

yak