LoginSignup
38
45

More than 5 years have passed since last update.

Windowsホスト上のVagrantのシンボリックリンクフォルダでyarn installできない問題の解決

Last updated at Posted at 2018-04-16

技術要件

  • Windows10
  • Ubuntu 16.04
  • vagrant 2.0.1
  • VirtualBox 5.1.26
  • Node.js 8.11.1
  • nvm 8.11.1
  • npm 5.8.0

問題

前の記事 『【Windows】nvm、npm、node.jsのインストール』で、
Windowsホスト上のVagrantに、Node.jsとそのまわりの必要なものたち、nvmとnpmを、無事にインストールすることができました。

そこで今度は、yarnのインストール…!
$ yarn install と叩きましたが、、、

$ yarn install
yarn install v1.5.1
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.1.3: The platform "linux" is incompatible with this module.
info "fsevents@1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@rails/webpacker > postcss-cssnext@3.0.2" has unmet peer dependency "caniuse-lite@^1.0.30000697".
warning " > webpack-dev-server@2.9.5" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
warning "webpack-dev-server > webpack-dev-middleware@1.12.2" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3
.0.0".
error An unexpected error occurred: "EPROTO: protocol error, symlink '../../../../js-yaml/bin/js-yaml.js' -> '/vagrant
/web/node_modules/@rails/webpacker/node_modules/.bin/js-yaml'".
info If you think this is a bug, please open a bug report with the information provided in "/vagrant/web/yarn-er
ror.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

無念のエラー。。。

“yarn プロトコルエラー”などで検索したところ、
$ yarn install --no-bin-linksでやるとできるとあったので、たたいてみるも、

$ yarn install --no-bin-links
yarn install v1.5.1
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.1.3: The platform "linux" is incompatible with this module.
info "fsevents@1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@rails/webpacker > postcss-cssnext@3.0.2" has unmet peer dependency "caniuse-lite@^1.0.30000697".
warning " > webpack-dev-server@2.9.5" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
warning "webpack-dev-server > webpack-dev-middleware@1.12.2" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3
.0.0".
[4/4] Building fresh packages...
[1/3] ⡀ uglifyjs-webpack-plugin
[2/3] ⡀ node-sass
[3/3] ⡀ styled-components
[-/3] ⡀ waiting...
error An unexpected error occurred: "/vagrant/web/node_modules/styled-components: Command failed.
Exit code: 127
Command: sh
Arguments: -c opencollective postinstall
Directory: /vagrant/web/node_modules/styled-components
Output:

やっぱりできない。。。
一体何がダメなんでしょう。。。

解決策

みている所が違った。
どうやら共有ファイルの設定が上手くいっていなかったらしいです。
Windowsファイルシステムに見つかるとパスの長さで怒られるので、見えないところでシンボリックリンクを許可します。

VirtualBoxから共有フォルダでシンボリックリンクを張れるよう設定

まずはVirtualBox側から許可するようにします。
Vagrantfileに以下の分を追加します。

config.vm.provider :virtualbox do |vb|
    vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/.","1"]
  end

Create以下のファイル指定はは自分の環境に合わせて変えてください。

Windowsから共有フォルダでシンボリックリンクを張れるよう設定

もしVagrantが起動させている状態でしたら、一度Vagrantをシャットダウンしてから行ってください。

まず、管理者権限のあるコマンドプロンプトを開いてください。
私は、Win + x Shift + a Alt + y で、管理者権限のあるPowerShellで作業しました。

開いたら、次のコマンドを実行してください。

$ fsutil behavior set SymlinkEvaluation L2L:1 R2R:1 L2R:1 R2L:1
$ fsutil behavior query symlinkevaluation
ローカルからローカルへのシンボリック リンクは有効です。
ローカルからリモートへのシンボリック リンクは有効です。
リモートからローカルへのシンボリック リンクは有効です。
リモートからリモートへのシンボリック リンクは有効です。

こうなったらOK!

いざ、yarn install

このまま管理者権限のあるコマンドプロンプトで、$ yarn installとたたいてください!

$ yarn install
yarn install v1.5.1
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.1.3: The platform "linux" is incompatible with this module.
info "fsevents@1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@rails/webpacker > postcss-cssnext@3.0.2" has unmet peer dependency "caniuse-lite@^1.0.30000697".
warning " > webpack-dev-server@2.9.5" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
warning "webpack-dev-server > webpack-dev-middleware@1.12.2" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
[4/4] Building fresh packages...
Done in 438.90s.

できました!!!

38
45
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
38
45