# TypeError: Discourse.\_registerPluginCode is not a function

**URL:** https://meta.discourse.org/t/typeerror-discourse-registerplugincode-is-not-a-function/88572
**Category:** Support
**Created:** [May 28, 2018, 8:06am UTC](https://meta.discourse.org/t/typeerror-discourse-registerplugincode-is-not-a-function/88572 "2018-05-28T08:06:21Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![amotl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/amotl/32/109873_2.png) [@amotl](https://meta.discourse.org/u/amotl)
#### Post date: [January 15, 2019, 6:03am UTC](https://meta.discourse.org/t/typeerror-discourse-registerplugincode-is-not-a-function/88572/7 "2019-01-15T06:03:49Z")

</div>

By pulling together some [educated guessing](https://www.destroyallsoftware.com/talks/wat), improved [duck typing](https://en.wikipedia.org/wiki/Duck_typing) and a bit of [monkey patching](https://en.wikipedia.org/wiki/Monkey_patching) as @sam already might have suggested by his comment referenced above (thanks for the valuable hint!), we have been able to find the root cause and to provide a drop-in workaround.

## Root cause

The root cause must be elsewhere, we just added an appropriate topic outlining our observations.

> [@Almost void Discourse object instance will sneak through some safeguards](https://meta.discourse.org/t/almost-void-discourse-object-instance-will-sneak-through-some-safeguards/106553):
>
> Hi there, while investigating the root cause of [TypeError: Discourse.\_registerPluginCode is not a function - #2 by amotl](https://meta.discourse.org/t/typeerror-discourse-registerplugincode-is-not-a-function/88572/2), we found that while running through its initialization phase, Discourse introduces itself as a rather void object on all static or no\_ember pages (we learned that jargon while reading here, apologies when we’re getting something wrong) rather than being just undefined: » Discourse » \> Object { SiteSettings: {} } This will make it easy to sneak through safeguards like "if (…

## Workaround

When running this snippet in the `Header` phase (`</head>` will be too early!) of a theme component, it makes this error go away by monkey patching the ill-called `_registerPluginCode` method as a `noop`. The safeguards mentioned above will be able to do their jobs again and not croak on the browser console.

```plaintext
<!--
Work around `TypeError: Discourse._registerPluginCode is not a function`, see also:
- https://meta.discourse.org/t/typeerror-discourse-registerplugincode-is-not-a-function/88572
- https://meta.discourse.org/t/javascript-not-loading-on-certain-pages/92297
-->
<script language="javascript">
    if (!('Discourse' in window)) {
        window.Discourse = {};
    }
    if ('Discourse' in window && !('_registerPluginCode' in window.Discourse)) {
        // Make this a noop
        window.Discourse._registerPluginCode = function() {};
    }
</script>

```

---

_[View the full topic](https://meta.discourse.org/t/typeerror-discourse-registerplugincode-is-not-a-function/88572)._
