chunks.some is not a function

768 Views Asked by At

I have just upgraded from webpack 4 to webpack 5 but now when I try to build my solution, it's throwing the following error:

TypeError: chunks.some is not a function

This is the line in my webpack.config:

  optimization: {
    splitChunks: {
      cacheGroups: {
        vendor: {
          name: 'vendor',
          chunks: 'all',
          reuseExistingChunk: true,
          priority: 100,
          enforce: true,
          test(module, chunks) {
            const name = module.nameForCondition && module.nameForCondition();
            return chunks.some(chunk => {
              return (/[\\/]node_modules[\\/]/.test(name)
                || /[\\/]vendor[\\/]/.test(name));
            });
          }
        },

Does anyone know what this has been replaced with or how I can change the above so it will work?

1

There are 1 best solutions below

0
On BEST ANSWER

I managed to fix it by using the following:

splitChunks: {
  cacheGroups: {
    vendor: {
      name: 'vendor',
      chunks: 'all',
      reuseExistingChunk: true,
      priority: 100,
      enforce: true,
      test: /[\\/]node_modules[\\/]|vendor[\\/]/,
    },
  },
},