Skip to content

TypeError: Cannot read properties of undefined (reading 'options') on Rsbuild #211

@2dragonly

Description

@2dragonly

Steps to reproduce

import {
  type EnvironmentConfig,
} from "@rsbuild/core";
import imagemin from "unplugin-imagemin";

//config code, here...

const webConfig: EnvironmentConfig = {
        html: { template: config.htmlTemplate },
        source: { entry: { index: config.entry } },
        output: {
          target: "web",
          polyfill: "usage",
          legalComments: "none",
          assetPrefix: process.env?.VERCEL_PROJECT_PRODUCTION_URL
            ? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
            : "/",
          distPath: {
            root: config.output.distPath,
            svg: "static/img",
            image: "static/img",
          },
          minify: config.isProdBuild,
          sourceMap: !config.isProdBuild,
          filename: config.isProdBuild
            ? {
                js: "[name].[contenthash:8].js",
                css: "[name].[contenthash:8].css",
                font: "[name][ext]",
                image: "[name].[contenthash:8][ext]",
                svg: "[name].[contenthash:8][ext]",
                assets: "[name].[contenthash:8][ext]",
              }
            : {
                js: "[name].js",
                css: "[name].css",
                font: "[name][ext]",
                image: "[name][ext]",
                svg: "[name][ext]",
                assets: "[name][ext]",
              },
        },
        performance: {
          removeConsole: config.isProdBuild,
          chunkSplit: {
            strategy: "custom",
            splitChunks: {
              chunks: "all",
              minChunks: 1,
              cacheGroups: {
                vendor: {
                  test: /[\\/]node_modules[\\/]/,
                  name: "lib-vendors",
                  chunks: "all",
                  priority: 10,
                  reuseExistingChunk: true,
                },
                react: {
                  test: /node_modules[\\/](?:react|react-dom|scheduler|react-refresh)[\\/]/,
                  name: "lib-react",
                  chunks: "all",
                  priority: 20,
                },
                router: {
                  test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
                  name: "lib-router",
                  chunks: "all",
                  priority: 20,
                },
                utils: {
                  name: "lib-common",
                  minChunks: 2,
                  chunks: "all",
                  priority: 5,
                  reuseExistingChunk: true,
                },
              },
            },
          },
          preload: {
            type: "all-chunks",
          },
          prefetch: {
            type: "all-chunks",
          },
        },
        tools: {
          rspack(_config, utils) {

            _config.plugins ??= [];
            _config.plugins.push(imagemin.webpack({}))
          },
        },
      };

rsbuild dev or rsbuild build

What is expected?

successfully compressed images

What is actually happening?

Rsbuild v1.7.3

start   build started...
TypeError: Cannot read properties of undefined (reading 'options')
    at Context.generateDefaultValue (file:///Users/2dragonly/Documents/Projects/kfsdu931/node_modules/unplugin-imagemin/dist/chunk-NJT32BLA.mjs:1246:69)
    at Context.loadBundleHook (file:///Users/2dragonly/Documents/Projects/kfsdu931/node_modules/unplugin-imagemin/dist/chunk-NJT32BLA.mjs:1142:25)

System Info

System:
    OS: macOS 26.3
    CPU: (10) arm64 Apple M2 Pro
    Memory: 1.89 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 25.6.0 - /opt/homebrew/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 11.8.0 - /opt/homebrew/bin/npm
    pnpm: 10.28.0 - /usr/local/bin/pnpm
    bun: 1.3.5 - /Users/lazuee/.bun/bin/bun
  Browsers:
    Chrome: 144.0.7559.110
    Safari: 26.3
  npmPackages:
    @babel/preset-env: ^7.29.0 => 7.29.0 
    @babel/preset-react: ^7.28.5 => 7.28.5 
    @rsbuild/core: ^1.7.3 => 1.7.3 
    @rsbuild/plugin-babel: ^1.1.0 => 1.1.0 
    @rsbuild/plugin-react: ^1.4.5 => 1.4.5 
    react: ^19.2.4 => 19.2.4 
    react-dom: ^19.2.4 => 19.2.4 
    react-router: ^7.13.0 => 7.13.0 
    unplugin-imagemin: ^0.7.0 => 0.7.0

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions