1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WSL 環境から Windows プラットフォーム用の node.exe を使用する

Last updated at Posted at 2017-10-14

Windows 10 Fall Creators Update で WSL (Windows Subsystem for Linux) がいよいよ正式版になります!!

ということで、Insider Preview を使って WSL 上で Ruby on Rails を動かしてみています。 で、bin/rails server コマンドを実行すると以下のようなエラーが発生しました。

nobuoka@aira:~/rails-sandbox$ bin/rails server
/home/nobuoka/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/runtime.rb:85:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)
Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.

エラーメッセージにあるように、JS の実行環境が見つからない、ってことですね。 リンク先を見ると Node.js があると良さそうです。

さて、Windows 10 を使っている開発者の場合、Windows プラットフォーム用の Node.js をインストールしている人も多いと思います。 私もそうです。 そういう場合に、WSL 用に Linux 向けの Node.js バイナリも配置するのはちょっと面倒な気もしますよね。 WSL からは Windows の exe ファイルも実行できるので、下記のようなシェルスクリプト (名前を node にする) をパスが通ってる場所に配置することで WSL の Rails からも Windows 用の Node.js バイナリを使えるようになります! やったね!

# !/bin/sh
node.exe "$@"

多分大丈夫な気がしてるけど、もしかしたら何かプラットフォーム間の差異で問題が起こるかもしれないので自己責任でどうぞ。 → と思ったけど Rails で使うと普通にネイティブモジュールを使おうとしておかしくなるから Rails で使う場合は Linux 用の Node.js バイナリが必要でした :sob:

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?