开发者问题收集

Laravel Mix 未知选项‘--hide-modules’错误

2021-09-17
69395

当我尝试在 Laravel 项目中使用 Laravel Mix 编译 React 组件时,它会引发错误 2 生命周期。

E:\MY PROJECTS\Samriddhi Institute> npm run dev

@ dev E:\MY PROJECTS\Samriddhi Institute npm run development

@ development E:\MY PROJECTS\Samriddhi Institute cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/ setup/webpack.config.js

[webpack-cli] Error: Unknown option '--hide-modules' [webpack-cli] Run 'webpack --help' to see available commands and options npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! @ development: cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=no de_modules/laravel-mix/setup/webpack.config.js npm ERR! Exit status 2 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.

npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\RADHESHYAM\AppData\Roaming\npm-cache_logs\2021-09-17T05_52_36_957Z-debug.log npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! @ dev: npm run development npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the @ dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\RADHESHYAM\AppData\Roaming\npm-cache_logs\2021-09-17T05_52_37_148Z-debug.log PS E:\MY PROJECTS\Samriddhi Institute>"

图像上显示错误

3个回答

摘自文档: https://github.com/laravel-mix/laravel-mix/blob/master/UPGRADE.md

Update Laravel Mix

npm install --save-dev laravel-mix@latest

Update Your NPM Scripts

If your build throws an error such as Unknown argument: --hide-modules , the scripts section of your package.json file will need to be updated. The Webpack 5 CLI removed a number of options that your NPM scripts was likely referencing.

While you're at it, go ahead and switch over to the new Mix CLI.

Before

"scripts": {
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "npm run development -- --watch",
    "watch-poll": "npm run watch -- --watch-poll",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
    "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"
}

After

"scripts": {
    "dev": "npm run development",
    "development": "mix",
    "watch": "mix watch",
    "watch-poll": "mix watch -- --watch-options-poll=1000",
    "hot": "mix watch --hot",
    "prod": "npm run production",
    "production": "mix --production"
},
2021-09-17

我遇到了这个问题,并通过将 laravel-mix 降级到

“laravel-mix”:“^5.0.9”

然后运行:

npm install
解决了它
Yvan Rugwe
2022-02-14

从你的 package.json 中删除 --hide-modules,然后运行 ​​npm run dev,它将正常运行。

Ahmed Memon
2022-06-25