elm-format icon indicating copy to clipboard operation
elm-format copied to clipboard

Not working with visual studio code when installed from npm

Open Kurren123 opened this issue 6 years ago • 12 comments

On the vs code terminal: npm install elm-format -g Then reset the terminal. elm-format works fine when opened in CMD or powershell from any folder. I can use it to format any elm file. However when I select elm format from the vs code command palette (ctrl+shift+p) I get the following error:

image

Nothing actually happens to the code file. Also format on save doesn't work (despite the option being turned on from the workspace settings).

Thanks!

Kurren123 avatar Aug 09 '17 13:08 Kurren123

Which VSCode Elm/elm-format plugin(s) are you using? If you are able to run elm-format from your terminal, then this seems like an issue with the plugin.

avh4 avatar Aug 10 '17 01:08 avh4

VS Code 1.14.2
elm 0.12.1
elm-format 0.1.0

Kurren123 avatar Aug 10 '17 13:08 Kurren123

I'm having the same issue. I have installed elm-format with npm, can use elm-format from the command line, have verified that C:\Users\Travis\AppData\Roaming\npm\elm-format.cmd exists and that C:\Users\Travis\AppData\Roaming\npm is in my PATH. I tried restarting vscode and even logging off but vscode is still saying:

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

Any ideas are greatly appreciated. Would be great to be able to use elm formatting while I'm learning elm.

travisstaloch avatar Aug 30 '17 23:08 travisstaloch

You can use elm vscode plugin for formatting elm, after you install it use Alt+Shift+F (shortcut for "Format Document") to run elm-format.

The instructions in the README are out of date, elm-format has been unpublished from vscode-marketplace

oren-l avatar Oct 08 '17 21:10 oren-l

I still have this problem, is there any solution/workaround?

@oren-l this is happening with the elm vscode plugin, not elm-format. It still uses the elm-format package (not vscode plugin).

erikhofer avatar Feb 19 '19 10:02 erikhofer

I have a workaround if this is the same issue as #408

Swiftaff avatar Mar 02 '19 16:03 Swiftaff

I'm having this same issue on a new project. Something tells me I've solved this before with some VSCode specific configuration but nothing I've tried so far is working yet.

jpierson avatar Mar 30 '19 10:03 jpierson

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

jpierson avatar Mar 30 '19 11:03 jpierson

Any workaround for formatting?

rokit avatar Apr 16 '19 03:04 rokit

If your running linux, you need to add the full path to your elm-format like /home/razze/.nvm/versions/node/v10.15.3/bin/elm-format

As the path environment that vscode initalizes when you create a child_process with node does not include the nvm (or node?) part of your path variable...

razzeee avatar May 19 '19 23:05 razzeee

Same problem here =/

I Fixed my problem doing this I upgraded my version of elm-format and its come works now.

PS I changed npm to yarn.

I used yarn to install global follwing this link Yarn

1. yarn config set prefix ~/.yarn  (To created a myglobal yarn directory)
2. sudo yarn global add elm-format
3. ls ~/.yarn
4. elm-format

Bernardoow avatar Sep 16 '19 21:09 Bernardoow

I encountered this issue out of nowhere, tried reinstalling via npm, restarting everything, full path in extension setting but it just wouldn't work.

Turns out elm-format only works for me if I start VS Code from my project directory. I normally open it with code . and it works but if I start VS Code some other way it doesn't. YMMV. I'm running OS X.

mwaf avatar Feb 05 '21 11:02 mwaf