Open feluxe opened 7 years ago
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:
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.
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
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 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.
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:
This is the VS Code error message:
@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
Absolute paths to npm install
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:
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:
Here is the stdout
of child_process.exec()
:
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.
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?
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.
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.
@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.
@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?
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.
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)
Hi there!
I just installed elm-format like this:
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:
Now if I save an elm file in Atom I get this error: