shellscape / webpack-manifest-plugin

webpack plugin for generating asset manifests
MIT License
1.43k stars 186 forks source link

add check for chunks before checking length #224

Closed ratherblue closed 3 years ago

ratherblue commented 3 years ago

This PR contains:

Are tests included?

Breaking Changes?

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

Description

I have a really basic webpack file with the following:

const path = require('path')
const ManifestPlugin = require('webpack-manifest-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

const config = {
  entry: {
    app: './src/app.js'
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'build')
  },
  module: {
    rules: [
      {
        test: /\.(less)$/,
        use: [
          'style-loader',
          MiniCssExtractPlugin.loader,
          'css-loader',
          'postcss-loader',
          'less-loader'
        ]
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: './styles.[contenthash].css'
    }),
    new ManifestPlugin()
  ]
}

module.exports = config

I get the following error when building:

[webpack-cli] TypeError: Cannot read property 'length' of undefined
    at /home/travis/build/ratherblue/boilerplate/node_modules/webpack-manifest-plugin/lib/plugin.js:129:39
    at Array.reduce (<anonymous>)
    at ManifestPlugin.<anonymous> (/home/travis/build/ratherblue/boilerplate/node_modules/webpack-manifest-plugin/lib/plugin.js:116:26)
    at Hook.eval [as callAsync] (eval at create (/home/travis/build/ratherblue/boilerplate/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/home/travis/build/ratherblue/boilerplate/node_modules/tapable/lib/Hook.js:18:14)
    at Compiler.emitAssets (/home/travis/build/ratherblue/boilerplate/node_modules/webpack/lib/Compiler.js:739:19)
    at /home/travis/build/ratherblue/boilerplate/node_modules/webpack/lib/Compiler.js:398:10
    at processTicksAndRejections (node:internal/process/task_queues:75:11)
npm ERR! code 1
npm ERR! path /home/travis/build/ratherblue/boilerplate
npm ERR! command failed
npm ERR! command sh -c webpack

Here are my dependencies:

  "dependencies": {
    "autoprefixer": "^10.0.1",
    "css-loader": "^5.0.0",
    "less": "^3.12.2",
    "less-loader": "^7.0.2",
    "mini-css-extract-plugin": "^1.2.1",
    "postcss": "^8.1.4",
    "postcss-less": "^4.0.0",
    "postcss-loader": "^4.0.4",
    "style-loader": "^2.0.0",
    "stylelint": "^13.7.2",
    "stylelint-config-standard": "^20.0.0",
    "webpack": "^5.2.0",
    "webpack-cli": "^4.1.0",
    "webpack-manifest-plugin": "^2.2.0"
  }
ratherblue commented 3 years ago

This is a webpack 5 compatibility fix. chunks appear to no longer be automatically generated

ratherblue commented 3 years ago

Going to close this since it's a webpack 5 issue