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
- Pass renameFilter as a function: (opts) => computedName.
- If using a module path, ensure the module has `export default function ...` (default export).
- 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
- Always default-export your custom filter module.
- Pass renameFilter as an inline function when possible to avoid module resolution ambiguity.
- Unit-test the filter module's default export before wiring it into the build.
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
- Expected a single child of the root
- Expected an svg element as the root child
- Duplicated icons in legacy folder. Either \n1. Remove these
- docs-infra: The title "${title}" is too long (${title.length
- docs-infra: Missing description in the page: ${location}\n
AI-assisted analysis of mui/material-ui@bdc96df2cb (2026-08-12).
Data as JSON: /api/errors/556ac062875dfc05.
Report an issue: GitHub.