8
5

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.

Laravel 6 で laravel/ui をインストールしたらwebpackがコンパイルできなかった

Posted at

前提

Laravel 6 から、認証機能を使うためには laravel/ui を追加インストールしなければいけなくなった。

公式ドキュメント

公式ドキュメントだとwebpackのコンパイルに関しては書かれておらず、UIを適用するには、以下のコマンドを実行する必要がある。

$ npm install
$ npm run dev

参考: [https://www.techiediaries.com/laravel-authentication-tutorial/](Laravel 6 Auth Tutorial: Login/Register/Password Reset UI)

エラー

実行しようとしたら、エラーが出た。

npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`

どうやら、以下が問題となっているらしい。

Error: Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime (72)

調べていくと、 node-sass を再インストールすればいいらしい。
が、 npm install -g node-sass で、再度エラー。

Error: EACCES: permission denied, mkdir /Users/xxx/node_modules/node-sass/build

権限関係ならと思い、 sudo してもだめ。
これは、そもそも npmをsudoでインストールしている と出てしまうらしい(?ちゃんと理解できてないかも?)

参照
Error: EACCES, mkdir '/usr/local/lib/node_modules/node-sass' - installing globally #1098 へのコメント
Resolving EACCES permissions errors when installing packages globally

解決方法

node バージョンマネージャーである nvm をインストールして、そこから改めて node をインストールする。
すでに npmsudo でダウンロードされていても大丈夫。

Github: nvm

nvm のインストール

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash

~/.bash_profile などに以下を追加

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

node-sass のインストール

npm install -g node-sass

コンパイル成功

$ npm install
$ npm run dev
8
5
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
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?