環境
- macOS Sierra 10.12.1
- Vagrant 1.8.7
- VitualBox 5.1.6
- CentOS 7.2.1511 x86_64
- Node.js 6.9.1
- NPM 3.10.8
内容
Reactの公式サイトのQUICK STARTをやろうと思って、Vagrantを立ち上げて共有フォルダで、create-react-app hello-world
ってやったらエラーになった。原因としては、共有ディレクトリの共有の速度の問題なのかもしれない。多分ね。
最初は、下記の設定でVagrantを立ち上げた。
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "geerlingguy/centos7"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.provision "shell", inline: <<-SHELL
yum update -y
yum group install "Development Tools" -y
timedatectl set-timezone Asia/Tokyo
localectl set-locale LANG=ja_JP.UTF-8
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum install nodejs -y
npm install -g create-react-app
SHELL
end
その後、ゲストOSにログイン後に、共有フォルダでcreate-react-appを実行した。
cd /vagrant/
create-react-app hello-world
結果、下記のエラーが出て失敗した。
npm ERR! Linux 3.10.0-327.3.1.el7.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "--save-dev" "--save-exact" "react-scripts"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! path /vagrant/hello-world/node_modules/react-scripts/node_modules/acorn-globals/node_modules/acorn/bin/acorn
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/vagrant/hello-world/node_modules/react-scripts/node_modules/acorn-globals/node_modules/acorn/bin/acorn'
npm ERR! enoent ENOENT: no such file or directory, chmod '/vagrant/hello-world/node_modules/react-scripts/node_modules/acorn-globals/node_modules/acorn/bin/acorn'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /vagrant/hello-world/npm-debug.log
npm ERR! code 1
むむむ。となって、ホストOS(Mac)とゲストOSでやってみるが、どちらも成功した。共有フォルダのみで発生しとるっぽい。
ファイルが無いって言われましてもと思いながら、ググったがヒットせず。
みんなこんな事せずに、ローカルでやってるよねって思いつつも、やりたいので、考えた結果、共有速度が間に合ってないのかと思い、synced_folderにtype: "nfs"
を追加してやってみたら成功した。
nfsの方が共有の速度が速いとのことで、推測だけど、chmodをした時にはまだ共有されてなくて、ファイルが無いのかなとなった。速度の問題ならPCによって成功しないのか?困ったもんだ。
なので、タイトルは「やってみる」にしとく。
ゲストOS側で、共有ディレクトリに行って、ファイルを作成した時の動きを意識したことがなかった。そのうち調べよう。
最終のVagrantfileは下記となりました。
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "geerlingguy/centos7"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.synced_folder ".", "/vagrant", type: "nfs"
config.vm.provision "shell", inline: <<-SHELL
yum update -y
yum group install "Development Tools" -y
timedatectl set-timezone Asia/Tokyo
localectl set-locale LANG=ja_JP.UTF-8
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum install nodejs -y
npm install -g create-react-app
SHELL
end