执行php artisan module:make Demand报错,找不到webpack.stub文件
问题原因及修复方案
可能原因
- 依赖包安装不完整:
nwidart/laravel-modules包在安装过程中因网络波动或中断,导致webpack.stub等 stub 文件未完全下载到本地。 - 包版本兼容问题:特定版本的
laravel-modules存在 stub 文件缺失的 bug,或是与当前 Laravel 版本不匹配引发异常。 - 手动误操作:曾修改过
vendor/nwidart/laravel-modules目录下的文件,不慎删除了webpack.stub。
修复步骤
方法1:重新安装依赖包
这是解决文件缺失问题最直接的方式:
- 删除项目根目录下的
vendor文件夹和composer.lock文件 - 执行命令
composer install重新安装所有依赖,完成后再次尝试执行php artisan module:make Demand
方法2:切换稳定版本安装
若为版本兼容问题,可指定匹配 Laravel 版本的稳定版:
- 修改
composer.json中nwidart/laravel-modules的版本号(比如 Laravel 10 对应"nwidart/laravel-modules": "^10.0",Laravel 9 对应"nwidart/laravel-modules": "^9.0") - 删除
composer.lock和vendor文件夹,执行composer install - 重新测试模块创建命令
方法3:手动补全缺失文件
若不想重新安装依赖,可手动创建webpack.stub文件:
- 打开路径
C:\xampp\htdocs\projects\kerman\amlak\vendor\nwidart\laravel-modules\src\Commands\stubs - 创建名为
webpack.stub的文件,填入以下默认内容:
const path = require('path'); const mix = require('laravel-mix'); /* |-------------------------------------------------------------------------- | Mix Asset Management |-------------------------------------------------------------------------- | | Mix provides a clean, fluent API for defining some Webpack build steps | for your Laravel application. By default, we are compiling the Sass | file for the application as well as bundling up all the JS files. | */ mix.js('Modules/{{ModuleName}}/Resources/assets/js/app.js', 'public/modules/{{ModuleName}}/js') .sass('Modules/{{ModuleName}}/Resources/assets/sass/app.scss', 'public/modules/{{ModuleName}}/css');
- 保存文件后,重新执行
php artisan module:make Demand
内容的提问来源于stack exchange,提问作者Mahmoud Khosravi
相关产品推荐
相关产品推荐

