Elm-format: Can't find the elm-format binary, check the "elm-format" package settings page

Created on 12 Sep 2017  路  23Comments  路  Source: avh4/elm-format

Hi there!

I just installed elm-format like this:

npm install -g elm-format@exp

on my Linux Mint machine.
I can now access the elm-format tool on my command line.

I ran this to install the elm-format atom plugin:

apm install elm-format

Now if I save an elm file in Atom I get this error:

Can't find the elm-format binary, check the "elm-format" package settings page

plugin issue

Most helpful comment

I had to use elm-format.cmd to get it working in Windows 10. 馃槖

Windows 10
Atom 1.21.0

All 23 comments

Same error. Windows 10. Atom 1.20.1 x64. $ elm-format works. Tried reinstalling several times.

Same here on Windows 10, VS Code 1.16.

Unable to execute elm-format. Please make sure you have elm-format on your PATH

Feeding it the full path to executable does not help.

I had to use elm-format.cmd to get it working in Windows 10. 馃槖

Windows 10
Atom 1.21.0

Same error for me on Mac OS 10.12.4, Atom 1.21.2

Ditto OSX 10.13.1, Atom 1.22.0-beta0

Did anyone happen to find a concrete solution to this problem?

The workaround is to first verify that you can run elm-format from the terminal, and if that works, then provide the full, absolute path to elm-format in the settings for the Atom elm-format plugin.

If people can also provide information to me about the following, then I can help improve the guidelines for elm-format plugin authors to help make sure that the path can be detected automatically in more cases:

  • how you installed elm-format (npm vs manual installation vs other package manager)
  • the path that you had to specify in the plugin config

Thanks!

@avh4 Providing the full path worked for me within the atom package, thanks for the help!

By the way, I installed using npm global installation, navigated to the .exe, and pasted that path into the atom package config.

#1 Install elm-format from terminal/command-line:

$ npm install -g elm-format

#2 Install atom-elm-format for Atom like this:

$ apm install elm-format

or from the Atom GUI, where File -> Settings -> Install and search for elm-format, then click the Install button

#3 Download the zipped version [it has only elm-format.exe inside]. Unzip it and place it on your PATH. That's it. Now should be able to save any .elm file inside Atom without any issues.

How to find the PATH (where the elm is installed):

write in command-line (for Windows):

$ where elm

should output sometning like this(but depends where elm is installed):
--> C:\Program Files (x86)\Elm Platform0.18bin\elm.exe

or write in terminal (for Linux/Mac):

$ which elm

should output sometning like this(but depends where elm is installed):
--> /usr/local/bin/elm

I had the same error and indeed npm install -g elm-format is all I had to do.

I think when people read the instructions and see 1. Install elm-format they might think "Oh, I already installed it" and in fact you have only installed the elm-format _plugin_ not the elm-format _npm binary_. Perhaps adding the command-line instruction npm install -g elm-format will help avoiding that confusion 馃

I started getting this after upgrading elm-format

From [email protected] to [email protected] (released 2018-09-13)

Installed with yarn global add [email protected]

Using VSCode 1.27.2

Using VSCode Elm extension v0.21.0 (released 2018-08-30)

It is in my PATH

I've played around with many potential settings for elm.formatCommand, but just elm-format was what worked before I upgraded.

Downgrading back to 0.7.0-exp or 0.8.0 makes it work again. 0.8.1-rc1 is broken. 0.8.0 is currently latest.

(Unfortunately, 0.8.1 has a bugfix I need.)

Edit: The VSCode extension knows about this problem and has a fix planned, but not quite released: https://github.com/Krzysztof-Cieslak/vscode-elm/issues/270 But the workaround there worked for me, and now I'm happily using 0.8.1-rc2. So my problem may have been different from others' here.

I have the same issue feluxe originally outlined.

I have elm-format accessible from the command line but the editor plugins fail to find the elm-format executable.

I have tried this with VS Code and the elm plugin (linked to from the install directions).

I have tried this with Atom and both the elm-format and the atom-beautify plugins (linked to from the install directions).

Windows: 7
Atom: 1.31.1
VS Code: 1.27.2

Elm: 0.19.0
elm-format: 0.8.1

I have tried installing elm through npm, yarn, and the msi installation wizard. I have tried installing elm-format with npm and via downloading the executable. Nothing has fixed the editor plugins problem.

This is the Atom error message:
image

This is the VS Code error message:
image

@DylanLester have you tried elm-format.cmd in the plug-in command setting?

@absynce I have tried the following using VS Code (restarting after each change):

Just the command

  • elm-format
  • elm-format.cmd
  • elm-format.exe

Absolute paths to npm install

  • C:\Users\Dylan\AppData\Roaming\npmelm-format
  • C:\Users\Dylan\AppData\Roaming\npmelm-format.cmd
  • C:\Users\Dylan\AppData\Roaming\npm\node_moduleselm-formatbinelm-format
  • C:\Users\Dylan\AppData\Roaming\npm\node_moduleselm-format\unpacked_binelm-format.exe

Navigating to the folder _C:\Users\Dylan\AppData\Roaming\npm_ and running .\elm-format or .\elm-format.cmd, both successfully run the program.

Interesting though, if I run the file with an Elm syntax error I get this message:
image
That may mean nothing but it could mean this catch all statement is hiding the error. That is just a guess though.

I cloned the VS Code plugin and ran the extension in debug mode.

The plugin runs elm-format --stdin --elm-version 0.19 --yes using node's library child_process.exec() which causes the error. The error is displayed below:

Error: Command failed: elm-format --stdin --elm-version 0.19 --yes
elmFormat.js:72
    at ChildProcess.exithandler (child_process.js:287:12)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.__dirname.ChildProcess._handle.onexit (internal/child_process.js:209:5)

The actual error object received from the child_process.exec() function (seen in the VS Code plugin code here) is displayed below:

{
  cmd: "elm-format --stdin --elm-version 0.19 --yes",
  code: 3221225477,
  killed: false,
  message: "Command failed: elm-format --stdin --elm-version 0.19 --yes",
  signal: null,
  stack: "Error: Command failed: elm-format --stdin --elm-version 0.19 --yes

    at ChildProcess.exithandler (child_process.js:287:12)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Socket.ChildProcess.spawn.stream.socket.on (internal/child_process.js:346:11)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at Pipe.Socket._destroy.cb._handle.close [as _onclose] (net.js:554:12)"
}

I googled the error message: "Error: Command failed child_process" and found this GitHub issue: https://github.com/nodejs/node-v0.x-archive/issues/4590. The last user in that thread suggests this is displaying false errors. When I view the stdout paramater from the child_process.exec() it appears to have formatted the Elm code correctly -- it appears to work.

This is the unformatted Elm code:
image

Here is the stdout of child_process.exec():
image

The same stdout from above:

module Main exposing (Model, init)


type alias Model =
    Int


init : Model
init =
    0

I'm not really sure what to do with that.

Nice find @DylanLester . I have had the same issue with Windows 7, VS Code 1.30.2, ELM 0.19. Tried variants of the "elm.formatCommand" using absolute paths and commands, and checked my PATH and tried setting editor.formatOnSaveTimeout to 1500, and 3000 to no avail.

So assuming the issue is with the Node false error I did a little more digging and settled on a clunky workaround, which is to alter this line https://github.com/Krzysztof-Cieslak/vscode-elm/blob/master/src/elmUtils.ts#L98 to if (err && err.message.substring(0,30) !== "Command failed: elm-format.cmd") { (i.e. "elm-format.cmd" is the value in my "elm.formatCommand".

And also https://github.com/Krzysztof-Cieslak/vscode-elm/blob/master/src/elmUtils.ts#L118-L120 to if ((stdout.substring(0, 6) === "ERRORS") && (err.message.substring(0, 30) === "Command failed: elm-format.cmd")) { reject(err); } else { resolve({ stdout: stdout, stderr: stderr }); }

These just ignore this specific error, and doesn't solve the underlying issue and I'm sure this is bad form and will come back to bite me, but posting in case this helps someone else not have to run elm-format in their build scripts like I've been doing, and can now get the benefit of using elm-format in the editor as intended :-)

After trying all of the above, what finally worked for me (in VS Code) was symlinking elm-format binary
sudo ln -s /opt/elm/elm-format /usr/local/bin/

I am working on MacOSX, Vscode.
How I worked it out is:
First, find where the elm-format is installed by which elm-format (of course, you have to install it first)
Second, in /usr/local/bin/, make a soft link to the file you find. ln -s "/usr/local/lib/node_modules/node/lib/node_modules/node/lib/node_modules/elm-format/bin/elm-format" elm-format

Maybe related to this issue reported for the vscode Elm extension?
https://github.com/Krzysztof-Cieslak/vscode-elm/issues/275

I tried various things with inconsistent results until I realized that in some cases I'd come back to the file minutes later and it would be formatted all of the sudden. Based on some other recommendations for configuration on Windows specifically I ended up with the following workspace settings for VSCode.

{
    "elm.compiler": ".\\node_modules\\.bin\\elm",
    "elm.makeCommand": ".\\node_modules\\.bin\\elm make",
    "elm.formatCommand": ".\\node_modules\\.bin\\elm-format",

    "[elm]": {
        "editor.formatOnSave": true,
        "editor.formatOnSaveTimeout": 20000
    },
}

Notice the Windows specific path separators used as well as the 20 second timeout value. At least on my local machine it appears that elm-format is taking around 13 seconds to process a somewhat largish file (2181 lines).

I confirm the issue, and that sudo ln -s /opt/elm/elm-format /usr/local/bin/ is a workaround.

The funny thing, is that I got the error after a couple of days using the elm-format package without any error. (It could be the installation of other package that are involved, not sure...)

Actually it doesn't work anymore :/, and now returns

elm-format exited with code 127.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

rtfeldman picture rtfeldman  路  4Comments

gabrielflorit picture gabrielflorit  路  7Comments

avh4 picture avh4  路  7Comments

rtfeldman picture rtfeldman  路  7Comments

avh4 picture avh4  路  5Comments