LoginSignup
2
1

VSCodeの拡張機能であるERB Formatter/Beautifyをインストールした時にエラーで少しハマったので、同様の問題で悩んでいる方のために解決策を共有したいと思います。
環境はmacM2です。

エラー

  • VSCodeの拡張機能からインストール
  • Gemfileに gem 'htmlbeautifier' を追記して bundle install
    これで動くはずなんですが、フォーマットを実行してみると以下のようなエラーが
Error occurred while formatting: Command failed with exit code 1
Failed with exit code: 1. '/Users/hogehoge/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/htm
lbeautifier-1.4.2/bin/htmlbeautifier:12:in `rescue in beautify':
Error parsing standard input: invalid byte sequence in US-ASCII on
line 1 (RuntimeError) from 

エラー文を見ると標準入力を解析する際にASCII以外の無効なバイトシーケンスがある的なことが書かれてるので、文字コードの設定でエラーが発生してるのかなと推測できます。

解決方法

ERB Formatter/BeautifyのREAD MEの下の方にKnown Issuesとして解決方法の記載がありました。
具体的な設定のやり方として

(1)⌘Pからsettings.jsonを開く
(2)⌘f でvscode-erb-beautifyを検索
(3)以下の通り記載

    "vscode-erb-beautify.customEnvVar": {
        "LC_ALL": "en_US.UTF-8"
    },

これで VSCodeを開き直したらうまく動きました。
参考にしたGithubのissueのリンクです↓。
https://github.com/aliariff/vscode-erb-beautify/issues/47

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1