2

问题:运行命令npm run watch抛出错误

54% building 35/41 modules 6 active /app/docroot/themes/custom/mytheme/node_modules/css-loader/index.js??ref--10-2!/app/docroot/themes/custom/mytheme/node_modules/postcss-loader/src/index.js??postcss5!/app/docroot/themes
 ERROR  Failed to compile with 1 errors          1:25:50 AM

 error 

Cannot read property 'map' of undefined

 15 assets

ERROR in Cannot read property 'map' of undefined
[Browsersync] Proxying: https://ps.lndo.site

仅当我的 webpack.mix.js 文件中包含以下代码时才会发生错误:

mix.imagemin({
  patterns: [{
    from: '**/*.{png,gif,jpg,jpeg,svg}',
    to: 'images/',
    context: 'src/images/'
  }, {
    from: '**/*.{png,gif,jpg,jpeg,svg}',
    to: 'images/',
    context: 'src/components/'
  }]
  });

删除上面的代码片段可以消除错误,但是这个项目的以前的开发人员有这个原因。

由于安全漏洞,我最近进行了更新,并设法调试了 Copy Plugin 引入了重大更改的另一个问题(已在上面的代码中更新)。但是我不确定我的所有配置是否正确。

这是我试过的:从命令行

rm -rf node_modules
rm package.lock
npm cache clean --force
npm install

这些是截至 2020 年 8 月 27 日的 package.json 中的包

"devDependencies": {
    "bootstrap": "^4.3.1",
    "browser-sync": "^2.26.12",
    "browser-sync-webpack-plugin": "^2.2.2",
    "copy-webpack-plugin": "^6.0.3",
    "cross-env": "^7.0.2",
    "husky": "^4.2.5",
    "imagemin-webpack-plugin": "^2.4.2",
    "jquery": "^3.5.1",
    "laravel-mix": "^5.0.4",
    "laravel-mix-imagemin": "^1.0.3",
    "popper.js": "^1.16.1",
    "pretty-quick": "^2.0.1",
    "resolve-url-loader": "^3.1.1",
    "sass": "^1.26.10",
    "sass-loader": "^8.0.2",
    "vue-template-compiler": "^2.6.11"
  },
"dependencies": {
    "throttle-debounce": "^2.3.0"
  }

更新的包如下

    "browser-sync": "^2.26.7",
    "copy-webpack-plugin": "^5.1.1",
    "husky": "^4.2.3",
    "jquery": "^3.5.0",
    "sass": "^1.26.3",

    "throttle-debounce": "^2.1.0"
4

3 回答 3

2

To me this looks like a bug in the laravel-mix-imagemin plugin. Its NPM page says that "The patterns parameter is automatically converted to an array". But this doesn't comply with the copy-webpack-plugin^6 you are using (which is used under the hood by laravel-mix-imagemin), as version 6 doesn't accept an array anymore. (Too bad the laravel-mix-imagemin plugin doesn't list its dependencies and their versions properly ...)

BTW: I had basically the same issue, and the error message you get is a catastrophe.

于 2020-10-05T11:50:13.070 回答
0

您可能对 webpack 的版本有疑问。这是我能做出的最好的猜测。如果此代码之前有效,那么这可能是一种可能性。

于 2020-08-31T00:00:21.670 回答
0

没有找到很好的答案,现在只是从 webpack mix 中删除了 imagemin 配置。修复了编译问题,但没有解决我原来的问题。

于 2020-09-07T01:03:23.547 回答