AUR0769
Error Message
AUR0769: Failed to initialize the platform object. The host element's ownerDocument does not have a defaultView, did you create the host from a DOMParser and forget to call adoptNode()?
Description
This error occurs during the setup of the application's root component (AppRoot) when Aurelia attempts to access the global window object (via hostElement.ownerDocument.defaultView). The error indicates that the defaultView property is missing or null on the document that owns the host element provided to aurelia.app({ host: ... }). This typically means the host element exists within a document context that is disconnected from the main browser window environment.
Cause
Host Created by
DOMParserwithout Adoption: Creating an HTML structure usingnew DOMParser().parseFromString(...)and then selecting a host element from the resulting document without importing or adopting that element into the maindocumentusingdocument.importNode()ordocument.adoptNode(). Elements parsed this way belong to a separate, disconnected document object initially.Host Created by
document.implementation.createHTMLDocument: Creating a full document usingdocument.implementation.createHTMLDocument()and using an element from this document as the host. Similar toDOMParser, this document is not the main browser document and lacks adefaultViewunless specifically associated with a browsing context.Running in Non-Browser Environment without Polyfills: Attempting to run Aurelia with
@aurelia/runtime-htmlin an environment that doesn't provide a standard DOM with awindow/defaultView(like certain server-side rendering scenarios or minimal JS environments) without appropriate polyfills or a compatible platform implementation.
Solution
Use
document.importNode(): If creating the host element or its parent structure usingDOMParserorcreateHTMLDocument, ensure you import the relevant node(s) into the maindocumentbefore passing the host element to Aurelia. Useconst importedNode = document.importNode(nodeFromParser, true);and appendimportedNodeto the live DOM.Select Host from Live DOM: Ensure the
hostelement provided toaurelia.app()is selected from the active browser document (e.g., usingdocument.getElementById,document.querySelector). Do not use elements directly from documents created in memory without importing them.Provide Correct Platform: In non-standard environments, ensure you provide a suitable
IPlatformimplementation that correctly polyfills or represents the necessary DOM and window features. For standard browser usage, this is typically not required.
Example
Debugging Tips
Inspect the
hostelement being passed toaurelia.app().Check
hostElement.ownerDocumentin the debugger.Verify that
hostElement.ownerDocument.defaultViewis the mainwindowobject and notnullorundefined.If the host is created dynamically, trace its origin. Ensure it was either created directly within the main
documentor properly imported/adopted usingdocument.importNodeordocument.adoptNode.
Last updated
Was this helpful?