0
0

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 1 year has passed since last update.

【Laravel-Mix】npm run productionしたらエラーが出た時の苦し紛れの解決方法

Posted at

###npm run productionしたらエラーが出た

Terminal
npm run production

##前提
Laravel 8.4
webpack-cli 4.9
Laravel-mix 5.1

Laravel-uiのLaravel-mixを使いたかった。

package.json
    "scripts": {
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    }

#苦し紛れの解決方法
###そうだ、Laravel-mixを最新にしよう

Terminal
npm install laravel-mix@latest

私の環境ではうまくいきました。

Terminal
   npm run production

   Laravel Mix v6.0.39   
✔ Compiled Successfully in 10197ms

ちなみに公式Docによるとlaravel-mixバージョン6以上の場合、

package.json
"scripts": {
    "development": "mix",
    "watch": "mix watch",
    "watch-poll": "mix watch -- --watch-options-poll=1000",
    "hot": "mix watch --hot",
    "production": "mix --production"
}

scriptsがこんなに綺麗になる。エラーも出ない。すごい(小並感)

##以下、解決するまで試したこと
###エラー文1

Terminal
[webpack-cli] Error: Unknown option '--no-progress'
[webpack-cli] Run 'webpack --help' to see available commands and options

⇒ package.jsonのscriptsから --no-progressを削除し、再実行

###エラー文2

Terminal
[webpack-cli] Error: Unknown option '--hide-modules'
[webpack-cli] Run 'webpack --help' to see available commands and options

⇒ package.jsonのscriptsから --hide-modulesを削除し、再実行

###--no-progressと--hide-modulesを消したscripts

package.json
    "scripts": {
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --config=node_modules/laravel-mix/setup/webpack.config.js"
    }

##エラー文3

Terminal
[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.module.rules[10] has an unknown property 'loaders'.

⇒ webpack.config.jsを確認したところ、'loaders'プロパティが見当たらない。

npm-moduleを削除し、npm installする

Terminal
rm node_modules
Terminal
npm install

その後も再びエラー文3が出る。

##おわり
バージョンの選択はやはり塩梅が難しい。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?