LoginSignup
16
8

More than 3 years have passed since last update.

【Laravel8】npm run dev (sh: mix: command not found)

Last updated at Posted at 2021-03-31

経緯

laravelでsassを使うためにnpmをいじっている際にエラーに遭遇しました。

環境

Laravel Framework 8.34.0

エラーの内容

以下がエラーの内容です。(抜粋)

$ npm run dev

> @ dev /folder/foo
> npm run development


> @ development /folder/foo
> mix

sh: mix: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! @ development: `mix`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the @ development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

mixのコマンドがないと言われてしまいました。これは参りました。

検証

以前は動いていたため、とりあえずlaravelのバージョンを7系に下げてもう一度実行。すると、今度はちゃんと動きました!

ということはバージョンが低いのでしょうか。

解決方法

バージョンを上げてみましょう。以下のコマンドを入力して実行します。

npm i --save-dev laravel-mix@latest && 
npm i --save-dev sass-loader@latest && 
npm i --save-dev postcss@latest && 
npm i --save-dev webpack@latest

さて、この状態でもう一度 npm run devを実行します。

$ npm run dev

> @ dev /folder/foo
> npm run development


> @ development /folder/foo
> mix


● Mix █████████████████████████ emitting (95%)  
 emit




● Mix █████████████████████████ done (99%) plugins 
 WebpackBar:done

今度はちゃんと実行できました!

おわりに

バージョンは最新に!そして古い記事には注意!

参考

Laravel, NPM: Command “mix” not found

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