Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
feluxe opened this issue Sep 12, 2017 · 30 comments

Comments

@feluxe
Copy link

feluxe commented Sep 12, 2017

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

@SimonAlling
Copy link

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

@foxbunny
Copy link

foxbunny commented Sep 24, 2017

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.

@absynce
Copy link

absynce commented Oct 6, 2017

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

Windows 10
Atom 1.21.0

@jperkinsx
Copy link

Same error for me on Mac OS 10.12.4, Atom 1.21.2

@mattjbrent
Copy link

Ditto OSX 10.13.1, Atom 1.22.0-beta0

@jonator
Copy link

jonator commented Feb 5, 2018

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

@avh4
Copy link
Owner

avh4 commented Feb 6, 2018

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!

@jonator
Copy link

jonator commented Feb 6, 2018

@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.

@AndrianV
Copy link

#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 Platform\0.18\bin\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

@svileng
Copy link

svileng commented Aug 17, 2018

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 🤔

@skyqrose
Copy link

skyqrose commented Sep 20, 2018

I started getting this after upgrading elm-format

From elm-format@0.7.0-exp to elm-format@0.8.1-rc2 (released 2018-09-13)

Installed with yarn global add elm-format@0.8.1-rc2

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.

@DylanLester
Copy link

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.

@DylanLester
Copy link

This is the Atom error message:
image

This is the VS Code error message:
image

@absynce
Copy link

absynce commented Oct 3, 2018

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

@DylanLester
Copy link

@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\npm\elm-format
  • C:\Users\Dylan\AppData\Roaming\npm\elm-format.cmd
  • C:\Users\Dylan\AppData\Roaming\npm\node_modules\elm-format\bin\elm-format
  • C:\Users\Dylan\AppData\Roaming\npm\node_modules\elm-format\unpacked_bin\elm-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.

@DylanLester
Copy link

DylanLester commented Oct 4, 2018

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: nodejs/node-v0.x-archive#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.

@Swiftaff
Copy link

Swiftaff commented Feb 2, 2019

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 :-)

@ArturMroz
Copy link

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/

@linjiang82
Copy link

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

@jpierson
Copy link

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

@jpierson
Copy link

jpierson commented Mar 30, 2019

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).

@dtrckd
Copy link

dtrckd commented Jan 24, 2020

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...)

@dtrckd
Copy link

dtrckd commented Jan 25, 2020

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

elm-format exited with code 127.

@Erudition
Copy link

Erudition commented Dec 7, 2021

On my new operating system Guix I'm installing everything locally (npm install elm-format without the -g which would not work) which works fine from the CLI but not in the editor (even with absolute path), I too see
elm-format exited with code 127.
What's code 127?

@avh4
Copy link
Owner

avh4 commented Dec 7, 2021

Exit code 127 means the executable is not found. So that sounds like a problem with the PATH. Though it's weird that it's the same error if you give the editor setting an absolute path to elm-format. Maybe node is not on the PATH? Having node on the path would be required when elm-format is installed via npm because the npm package installs a wrapper script around the compiled haskell binary.

@Erudition
Copy link

Ah! Yes, I'm not trying to have anything node-related on my global PATH (would relative entries be okay?) because I have node set up on a per-project (this folder only) development environment.

@avh4
Copy link
Owner

avh4 commented Dec 7, 2021

@Erudition in that case, you might want to use elm-tooling, which itself still uses node, but it will download the elm-format binary for you and put it in your project's node_modules and the result will not have a nodejs wrapper around elm-format, so your editor won't need node on the PATH to run elm-format.

@Erudition
Copy link

@avh4 you're the best! That worked like a charm. Can I get rid of the absolute path in the settings then? Have it just use the current project's elm-format in the portable way that elm-tooling is designed for?

@avh4
Copy link
Owner

avh4 commented Dec 7, 2021

The recommendation to plugin authors is that it should check ./node_modules/.bin/elm-format automatically if there's not an elm-format path explicitly set. Though I'm not sure which editor plugins have implemented that and which haven't. Hopefully it'll work that way if you try it.

@Erudition
Copy link

Erudition commented Dec 7, 2021

thanks. for the atom plugin, it seems the answer is currently no. setting it to blank means it does not find it at all, even though it exists where you describe. So I guess I can't use a per-project path right now. Had to use the elm-tooling user-wide path, ~/.elm/elm-tooling/elm-format/0.8.5/elm-format (where even ~ must be expanded)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests