{"record":{"id":"de9b43307dc9a146","repo":"ajaxorg/ace","slug":"couldn-t-load-module-theme-or-it-didn-t-ca","errorCode":null,"errorMessage":"couldn't load module \" + theme + \" or it didn't call define","messagePattern":"couldn't load module \" \\+ theme \\+ \" or it didn't call define","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/virtual_renderer.js","lineNumber":2043,"sourceCode":"        this.$themeId = theme;\n        _self._dispatchEvent('themeChange',{theme:theme});\n\n        if (!theme || typeof theme == \"string\") {\n            // @ts-ignore\n            var moduleName = theme || this.$options.theme.initialValue;\n            config.loadModule([\"theme\", moduleName], afterLoad);\n        } else {\n            afterLoad(theme);\n        }\n\n        /**\n         * @param {Theme} module\n         */\n        function afterLoad(module) {\n            if (_self.$themeId != theme)\n                return cb && cb();\n            if (!module || !module.cssClass)\n                throw new Error(\"couldn't load module \" + theme + \" or it didn't call define\");\n            if (module.$id)\n                _self.$themeId = module.$id;\n            dom.importCssString(\n                module.cssText,\n                module.cssClass,\n                _self.container\n            );\n            if (_self.theme)\n                dom.removeCssClass(_self.container, _self.theme.cssClass);\n            /**@type {any}*/\n            var padding = \"padding\" in module ? module.padding\n                : \"padding\" in (_self.theme || {}) ? 4 : _self.$padding;\n            if (_self.$padding && padding != _self.$padding)\n                _self.setPadding(padding);\n\n            if (_self.$gutterLayer) {\n                var showGutterCursor = module[\"$showGutterCursorMarker\"];\n                if (showGutterCursor && !_self.$gutterLayer.$showCursorMarker) {","sourceCodeStart":2025,"sourceCodeEnd":2061,"githubUrl":"https://github.com/ajaxorg/ace/blob/2c1eddc392eb92cf222a4478f1893d2b2c354fb0/src/virtual_renderer.js#L2025-L2061","documentation":"VirtualRenderer throws this Error when the theme module loaded asynchronously either failed to load or loaded without defining the expected API (a cssClass property). After $theme.loadModule resolves via afterLoad, a falsy module or a module missing cssClass means the theme script never registered itself (e.g., never called define).","triggerScenarios":"renderer.setTheme('ace/theme/Name') where the theme file does not exist at the resolved path, the CDN/network request fails, or the theme script is an old/incorrect build that doesn't call define() to export {cssClass, cssText}.","commonSituations":"Typo in theme name ('solarized_dark' vs 'solarized_dark'), self-hosting ace files with a broken path mapping for ace/theme/*, ad blockers or CSP blocking the theme script, or bundling ace without its theme modules.","solutions":["Verify the theme name/path exists, e.g. ace/theme/twilight — check the lib/ace/theme directory or CDN","Check the browser network/console for 404s or CSP blocks on the theme script","If self-hosting, configure the loader/basePath so 'ace/theme/x' resolves to the real theme file","Ensure the theme module is included in your bundle or set the theme to a known-good built-in like 'ace/theme/textmate'"],"exampleFix":"// before\neditor.setTheme('ace/theme/monokai_dark'); // doesn't exist\n// after\neditor.setTheme('ace/theme/monokai');","handlingStrategy":"fallback","validationCode":"var themeName = 'ace/theme/monokai';\nif (!/^ace\\/theme\\/[\\w-]+$/.test(themeName)) throw new Error('bad theme name');\n// verify availability if using ace's config: ace.config.loadModule(themeName, function(m){ if(!m) fallback(); });","typeGuard":"function isLoadedTheme(m) { return m && typeof m === 'object' && typeof m.cssClass === 'string' && m.cssClass.length > 0; }","tryCatchPattern":"try {\n  renderer.setTheme('ace/theme/mytheme');\n} catch (e) {\n  if (/couldn't load module/.test(e.message)) renderer.setTheme('ace/theme/textmate');\n  else throw e;\n}","preventionTips":["Use exact built-in theme names (twilight, monokai, textmate, ...)","When self-hosting, keep ace/theme/* files next to the core and set basePath correctly","Check DevTools network tab for 404s on theme scripts after setTheme","Pin ace and its themes to the same version"],"tags":["theme","module-loading","async","undefined"],"backgroundTag":"theme-module-load-failed","analyzedSha":"2c1eddc392eb92cf222a4478f1893d2b2c354fb0","analyzedAt":"2026-08-30T00:39:52.222Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}