This question has been answered. How to create Document objects with JavaScript
Check out MDN to learn how https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument
The new Document() constructor is not used like this. You can find the reason you are getting this error if you use the console in your browser...
let doc = new Document();
doc.body;
// < null
doc.doctype;
// < null
// doc.doctype is a read only property also.
doc.__proto__;
// < Document {…}
// ‘document’ is the document the browser already created.
document.doctype;
// < “<!doctype html>“
document.__proto__;
//HTMLDocument {constructor: ƒ, Symbol(Symbol.toStringTag): "HTMLDocument"}
let body1 = doc.createElement('body');
let body = document.createElement('body');
body1.__proto__;
// Element {…}
body.__proto__;
// < HTMLBodyElement {…}
doc.body = body1;
// < Type Error: Not of type HTMLElement
// Now use the body element created by 'document'.
doc.body = body;
// Uncaught DOMException: Failed to set the 'body' property on 'Document': No document element exists.
// The body needs an document element to become a child node of.
let html = document.createElement('html');
doc.appendChild(html);
doc.body = body;
// No errors
doc.body;
// <body></body>
As we can see the new Document() constructor makes a completely blank Document with a prototype of Document. And when you create elements from it those elements have a prototype of Element.
The Document the browser created named document has a prototype of HTMLDocument and the elements it creates have a prototypes of HTMLElement.
And this is what the setter of doc.body is looking for.