9
8

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.

Vagrant上のHomestead環境でReact入れようとしたらnpm installができない(できた)

Posted at

なんですかこれは

LaravelのWebアプリをVagrant上でsshで繋いで開発しているときに,フロントはReactで書きたい気分になりました.

LaravelでReactを使うのはとても簡単です.
以下のコマンドで即使えるようになります.完璧ですね.

php artisan preset react
npm install && npm run dev

というネットの話を信じて実行すると以下のようになりました.

npm ERR! path /home/vagrant/code/task/node_modules/yargs/node_modules/cliui/package.json.4000644436
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/home/vagrant/code/task/node_modules/yargs/node_modules/cliui/package.json.4000644436'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vagrant/.npm/_logs/2019-08-01T15_07_42_585Z-debug.log

...エラーメッセージが謎すぎる...
というわけで解決していきます.

実行環境

  • macOS mojave 16.14.5
  • Laravel 5.8
  • node v12.7.0
  • npm 6.10.0

解決法

以下の記事にて原因が究明されていたので参考にやってみました.

laracasts.com/discuss

原因としてはどうやら,仮想環境上だとnpmがうまく動きすぎる(原文: once I've move the project inside the VM, npm install works fine.)ということらしいです.
わけわかりません.

ひとまず仮想環境上ではなくホストOS上でnpmインストールを行います.
作業ディレクトリの共有ディレクトリに移動し,以下のコマンドを実行します.

php artisan preset react
npm install && npm run dev

するとインストールに成功しました!(Laravel mixのbuild成功というポップアップも出ました)

まとめ

根の深いミスじゃなくてよかった...
知らなかったんですが,仮想環境上で重たいインストールを行うのは負荷が大きいのでやめておいたほうがいいらしいですね.

9
8
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
9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?