mui/material-ui · error · Error

renameFilter must be a function

Error message

renameFilter must be a function

What it means

The icons builder accepts a `renameFilter` option that is either a function or a string path to a module whose default export is the function (it dynamically imports the string). After that resolution, if renameFilter is still not a function, it throws. The filter maps each SVG path to a destination filename/component name, so a non-function would silently break generation.

Source

Thrown at packages/mui-icons-material/builder.mjs:249

    componentName,
  });

  const absDestPath = path.join(options.outputDir, destPath);
  await fs.writeFile(absDestPath, fileString);
}

export async function handler(options) {
  const progress = options.disableLog ? () => {} : () => process.stdout.write('.');

  rimrafSync(`${options.outputDir}/*.js`, { glob: true }); // Clean old files

  let renameFilter = options.renameFilter;
  if (typeof renameFilter === 'string') {
    const renameFilterModule = await import(renameFilter);
    renameFilter = renameFilterModule.default;
  }
  if (typeof renameFilter !== 'function') {
    throw new Error('renameFilter must be a function');
  }
  await fs.mkdir(options.outputDir, { recursive: true });

  const [svgPaths, template] = await Promise.all([
    globAsync(normalizePath(path.join(options.svgDir, options.glob))),
    fs.readFile(path.join(currentDirectory, 'templateSvgIcon.js'), {
      encoding: 'utf8',
    }),
  ]);

  const queue = new Queue(
    (svgPath) =>
      worker({
        progress,
        svgPath,
        options,
        renameFilter,
        template,

View on GitHub (pinned to bdc96df2cb)

Solutions

  1. Pass renameFilter as a function: (opts) => computedName.
  2. If using a module path, ensure the module has `export default function ...` (default export).
  3. Verify the module path resolves and the default export is callable.

Example fix

// before — module has only a named export
// myFilter.js: export function myFilter(opts) { ... }
// caller: renameFilter: './myFilter.js'
// after
// myFilter.js: export default function myFilter(opts) { ... }
// caller: renameFilter: './myFilter.js'
Defensive patterns

Strategy: type-guard

Type guard

function isRenameFilter(value) {
  return typeof value === 'function';
}
// after resolving a string module path:
if (!isRenameFilter(renameFilter)) throw new Error('renameFilter resolved to a non-function');

Prevention

When it happens

Trigger: Passing options.renameFilter that is neither a function nor a resolvable module path; passing a module path whose default export is undefined or not a function; passing a plain object by mistake.

Common situations: Customising icon output paths/names with a user-supplied filter; the filter module was refactored to a named export instead of default; a CLI flag passed an object string that failed JSON.parse elsewhere.

Related errors


AI-assisted analysis of mui/material-ui@bdc96df2cb (2026-08-12). Data as JSON: /api/errors/556ac062875dfc05. Report an issue: GitHub.