提问人:XenoProxy 提问时间:11/11/2023 最后编辑:XenoProxy 更新时间:11/13/2023 访问量:138
TypeError:无法读取 undefined 的属性(读取“scripts”)
TypeError: Cannot read properties of undefined (reading 'scripts')
问:
我使用节点 v20.9.0、npm v10.1.0
当我运行 npm run watch 时,会抛出以下错误:
[webpack-cli]TypeError:无法读取 undefined 的属性(读取“scripts”) at 对象。(c:\OSPanel\domains\dispatcher\webpack.mix.js:16:4) 在 Module._compile (node:internal/modules/cjs/loader:1241:14) 在Module._extensions..js (节点:internal/modules/cjs/loader:1295:10) 在 Module.load (node:internal/modules/cjs/loader:1091:32) 在 Module._load (node:internal/modules/cjs/loader:938:12) 在 Module.require (node:internal/modules/cjs/loader:1115:19) 在需要(节点:内部/模块/助手:130:18) 在 module.exports (c:\OSPanel\domains\dispatcher\node_modules\laravel- mix\setup\webpack.config.js:11:5) 在 loadConfigByPath (c:\OSPanel\domains\dispatcher\node_modules\webpack-cli\lib\webpack-cli.js:1445:37) 在异步 Promise.all (索引 0)
我的package.json
"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"
},
"devDependencies":
"axios": "^1.6.1",
"bootstrap-sass": "^3.3.7",
"cross-env": "^5.0.1",
"jquery": "^3.1.1",
"laravel-mix": "^6.0.49",
"lodash": "^4.17.4",
"vue": "^2.1.10",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
}
我的webpack.mix.js
let mix = require('laravel-mix');
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css').
mix.scripts([
'public/test/jquery.easing.1.3.js',
'public/test/retina-1.1.0.min.js',
'public/test/jquery.cookie.js',
'public/test/styleswitch.js',
'public/test/jquery.smartmenus.min.js',
'public/test/jquery.smartmenus.bootstrap.min.js',
'public/test/owl.carousel.min.js',
'public/test/jflickrfeed.js',
'public/test/jquery.magnific-popup.min.js',
'public/test/jquery.isotope.min.js',
'public/test/swipe.js',
'public/test/jquery.sticky.js',
'public/test/main.js',
],
'public/js/all.js').mix.scripts([
'public/test/fileinput.min.js',
'public/test/inputmask.js',
'public/test/jquery.inputmask.js',
'public/test/flash_message.js',
'public/test/select2.min.js',
'public/test/ru.js',
'public/test/text_area_counter.js',
'public/test/text_area_counter.js',
'public/test/file_input.js',
], 'public/js/libs.js');
如何修复此错误?
我尝试重新安装 webpack-cli 并清除 npm 缓存(npm cache clean --force),但它没有帮助
答:
主要问题是 node-sass 和 node-gyp。重新安装 node-gyp 并将 laravel-mix 降级到 v1 并将 node 降级到 v16.20.2 解决了它
评论