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

11.3k Views Asked by At

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

7

There are 7 best solutions below

0
On

Problem solved!

I just took the first 2 lines out (paths) and now it works!

1
On

You're running an outdated version of Prettier. Please update again to the latest version, which is v1.6.1 (as of Sept. 13, 2017).
If you want to use v1.5.x on purpose, you can add the --no-config option to the additional_cli_args setting, and tell Prettier not to attempt to find config files.

json { "additional_cli_args": { "--no-config": "" } }

0
On

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

0
On

If someone is having trouble with this even now, it may help to know that Prettier requires node >= v10.

To get this to work, you may have to set your node version as >= 10, I personally prefer 12 or 13.

You can do this either by using nvm alias default 12 fornvm or n 12 for n

Now, update the user settings file to make sure prettier has the right paths to prettier and node. Find the paths to node and prettier using which

which prettier
which node

Add the paths and flags to auto format on save as desired

{
  "prettier_cli_path": "/Users/user/.nvm/versions/node/v12.13.1/bin/prettier",
  "node_path": "/Users/user/.nvm/versions/node/v12.13.1/bin/node",
  "auto_format_on_save": true,
  "format_on_save_extensions": ["tsx", "json"]
}

Now reload sublime

0
On

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.

0
On

In my case, I had to fully restart Sublime 3 after it has installed a new Sublime version.

0
On

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