{"record":{"id":"4f0c28dd126e1f4d","repo":"MagicMirrorOrg/MagicMirror","slug":"failed-to-revive-function-for-config-key-key","errorCode":null,"errorMessage":"Failed to revive function for config key \"${key}\".","messagePattern":"Failed to revive function for config key \"(.+?)\"\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"js/main.js","lineNumber":462,"sourceCode":"\t});\n}\n\n/**\n * Loads the core config from the server (already combined with the system defaults).\n */\nasync function loadConfig () {\n\ttry {\n\t\tconst res = await fetch(new URL(\"config/\", `${location.origin}${config.basePath}`));\n\n\t\t// The server tags functions as { __mmFunction: \"<source>\" } because\n\t\t// JSON.stringify can't serialise live functions. This reviver turns\n\t\t// those tagged objects back into callable functions.\n\t\tconfig = JSON.parse(await res.text(), (key, value) => {\n\t\t\tif (value && typeof value === \"object\" && typeof value.__mmFunction === \"string\") {\n\t\t\t\ttry {\n\t\t\t\t\treturn new Function(`return (${value.__mmFunction})`)();\n\t\t\t\t} catch {\n\t\t\t\t\tLog.warn(`Failed to revive function for config key \"${key}\".`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn value;\n\t\t});\n\t} catch (error) {\n\t\tLog.error(\"Unable to retrieve config\", error);\n\t}\n}\n\n/**\n * Adds special selectors on a collection of modules.\n * @param {Module[]} modules Array of modules.\n */\nfunction setSelectionMethodsForModules (modules) {\n\n\t/**\n\t * Filter modules with the specified classes.\n\t * @param {string|string[]} className one or multiple classnames (array or space divided).","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/MagicMirrorOrg/MagicMirror/blob/4b4a59534f7da01e4030e46029fe9dd649a7675e/js/main.js#L444-L480","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconfig: {\n  customTitle: () => `Weather for ${cityName}` // closes over cityName\n}\n// after\nconfig: {\n  customTitle: function () { return \"Weather for \" + \"Berlin\"; } // self-contained, no outer refs\n}","handlingStrategy":"fallback","validationCode":"// in config.js, before shipping a function value, self-test it:\nconst fn = function () { return \"Berlin\"; };\nfn(); // must not throw, and must not reference outer-scope vars\nconsole.log(fn.toString()); // inspect for external references","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["config","serialization","function-revival"],"backgroundTag":"function-serialization-failed","analyzedSha":"4b4a59534f7da01e4030e46029fe9dd649a7675e","analyzedAt":"2026-08-31T21:49:42.591Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}