MagicMirrorOrg/MagicMirror · warning
Failed to revive function for config key "${key}".
Error message
Failed to revive function for config key "${key}". What it means
When MagicMirror loads its config over HTTP, serialized function values arrive as objects tagged with a __mmFunction string. loadConfig attempts to rebuild each one with new Function(). If the source string fails to compile or evaluate (syntax error or reference to undefined globals), the reviver logs this warning and keeps the raw tagged object in its place, so the module config silently lacks the intended callback.
Source
Thrown at js/main.js:462
});
}
/**
* Loads the core config from the server (already combined with the system defaults).
*/
async function loadConfig () {
try {
const res = await fetch(new URL("config/", `${location.origin}${config.basePath}`));
// The server tags functions as { __mmFunction: "<source>" } because
// JSON.stringify can't serialise live functions. This reviver turns
// those tagged objects back into callable functions.
config = JSON.parse(await res.text(), (key, value) => {
if (value && typeof value === "object" && typeof value.__mmFunction === "string") {
try {
return new Function(`return (${value.__mmFunction})`)();
} catch {
Log.warn(`Failed to revive function for config key "${key}".`);
}
}
return value;
});
} catch (error) {
Log.error("Unable to retrieve config", error);
}
}
/**
* Adds special selectors on a collection of modules.
* @param {Module[]} modules Array of modules.
*/
function setSelectionMethodsForModules (modules) {
/**
* Filter modules with the specified classes.
* @param {string|string[]} className one or multiple classnames (array or space divided).View on GitHub (pinned to 4b4a59534f)
Solutions
- Make the function value self-contained: no references to variables outside its own body (no closures over config.js scope, no imports).
- Check the browser/devtools console for the underlying SyntaxError or ReferenceError when the function is evaluated.
- Replace the dynamic function with a plain value or a supported option name accepted by the module.
- Update MagicMirror core if using an older serialization scheme; __mmFunction handling has changed across versions.
Example fix
// before
config: {
customTitle: () => `Weather for ${cityName}` // closes over cityName
}
// after
config: {
customTitle: function () { return "Weather for " + "Berlin"; } // self-contained, no outer refs
} Defensive patterns
Strategy: fallback
Validate before calling
// in config.js, before shipping a function value, self-test it:
const fn = function () { return "Berlin"; };
fn(); // must not throw, and must not reference outer-scope vars
console.log(fn.toString()); // inspect for external references Prevention
- Never let function config values close over variables from config.js scope
- Avoid imports/requires inside function config values
- After editing config.js, open the browser console and check for this warning
- Prefer plain values or supported module options over inline functions
When it happens
Trigger: A config.js value is a function (e.g. calendarfetchOptions, a custom formatter) whose source string throws when evaluated via new Function("return (...)")(); typically because the function closes over variables not present in the evaluation scope or contains invalid syntax after serialization.
Common situations: Using arrow functions or functions referencing outer-scope helpers/constants defined elsewhere in config.js; hand-editing config.js and introducing a syntax error inside a function value; copying config snippets that rely on imported modules.
Related errors
- Latitude and longitude are required
- Unknown weather type: ${this.config.type}
- siteCode and provCode are required
- Unknown weather type: ${this.config.type}
- setCallbacks() must be called before initialize()
AI-assisted analysis of MagicMirrorOrg/MagicMirror@4b4a59534f (2026-08-31).
Data as JSON: /api/errors/4f0c28dd126e1f4d.
Report an issue: GitHub.