How to add Prettier JS as a formatter

I have tried adding in a custom formatter for Javascript, using Prettier (

I installed prettier globally via npm
npm install -g prettier

In the preferences I added a new custom formatter for .jsx files.

Name: Prettier
Language: JSX
Formatter: Other / Generic Command Line Formatter

Executable To Use: C:\path\to\npm\node_modules\prettier\bin-prettier.js (Also tried standalone.js and index.js)
Command Line Arguments: write

When I try to format code I get a windows script host error dialog box pointing to line 169 char 2 of prettier index.js. Expected identifier, string or number.

I get the particular error is not anything to do with Komodo but I’m wondering if all my config is correct and if anyone else has had success setting up a custom formatter for Prettier?

@stereofx, Komodo can only run a binary in this context. I believe the binaries live in .../node_modules/.bin. Point to the Prettier binary that should be there.

That should get you closer.

  • Carey

@careyh thanks for the suggestion. Looks like Prettier’s binary just executes the JS index file, so same error - just thought I would let you know. I could add this to the feature ideas section.

That is what I’d expect it to do. What errors are you getting?

In Komodo here is the error output:

[2018-10-17 10:49:08,548] [ERROR] ko.formatters: Formatting failed
[Exception… “Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [koIFormatter.format]” nsresult: “0x80004005 (NS_ERROR_FAILURE)” location: “JS frame :: chrome://komodo/content/formatters/formatters.js :: _formatViewWithFormatterAndContext :: line 135” data: no]

  • toString (function) 3 lines
  • message (string) ‘Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [koIFormatter.format]’
  • result (number) 2147500037
  • name (string) ‘NS_ERROR_FAILURE’
  • filename (string) ‘chrome://komodo/content/formatters/formatters.js’
  • lineNumber (number) 135
  • columnNumber (number) 0
  • inner (object) null
    | + data (object) null
    | + stack (string) ‘_formatViewWithFormatterAndContext@chrome://komodo/content/formatters/formatters.js:135:16
    formatVie’…477 chars
  • location (object) JS frame :: chrome://komodo/content/formatters/formatters.js :: _formatViewWithFormatterAndContext :: line 135
    | + QueryInterface (function) 3 lines
    | + language (number) 2
    | + languageName (string) ‘JavaScript’
    | + filename (string) ‘chrome://komodo/content/formatters/formatters.js’
    | + name (string) ‘_formatViewWithFormatterAndContext’
    | + lineNumber (number) 135
    | + columnNumber (number) 16
    | + sourceLine (string) ‘’
    | + caller (object) JS frame :: chrome://komodo/content/formatters/formatters.js :: formatView :: line 728
    | + formattedStack (string) ‘_formatViewWithFormatterAndContext@chrome://komodo/content/formatters/formatters.js:135:16
    formatVie’…477 chars
    | + stack
    [2018-10-17 10:49:08,671] [ERROR] socket-tcp: Error occurred: error : NetworkError
    Traceback from ERROR in ‘socket-tcp’ logger:

And I get a windows script execution error as well. See screenshot.

Could you try the command in the terminal and see what happens? The fact that you’re getting a Windows error tells me there is something wrong with the way you’re using the formatter.

Given the fields you filled in for the custom formatter it would be something like:

> bin-prettier.cmd write path\to\file.js
  • Carey

By terminal, I assume you are referring to the windows terminal (not Komodo terminal).

bin-prettier.cmd errors because the file in the node_modules bin directory is just a symlink to Prettier’s index js file, not an actual cmd file - I guess that could be a problem.

You should be able to see the commands I entered in the screenshot, none of them worked and I keep getting the windows error, but slightly different now.

So they are putting a non-binary/terminal ready file into the bin folder? I can’t help there then. You need a file that is executable by your terminal. If you can figure out how to install the prettier formatter that way then you’ll be set.

FYI: this works excellently for me. (linux / komodo-ide 11.1.1)

  1. install prettier globally
    $ npm i prettier -g

  2. Komodo: Preferences -> Formatters -> [+]
    Name: Prettier
    Language: JavaScript
    Formatter: Generic command-line formatter

  3. In “Configurable Options”
    Executable to use:
    Command-line arguments:
    --stdin-filepath %f

  4. Click “OK”

  5. Click “Apply”

Right click in a JS file -> Format -> Document using -> Prettier

1 Like