{"id":16053,"library":"html-element","title":"HTML Element Shim for Server-Side Templating","description":"html-element is a server-side shim providing a partial implementation of `HTMLElement` for Node.js environments. It enables client-side templating libraries, such as Hyperscript, to execute server-side without a full browser DOM. The current stable version is 2.3.1, released in August 2016. The project appears to be in an abandoned state with no significant updates since 2017, making its release cadence non-existent. Its primary differentiation is its lightweight nature, offering just enough DOM API to render templates without the overhead of a headless browser, focusing on core element creation, manipulation, and serialization methods like `createElement`, `appendChild`, `setAttribute`, and `toString()`. It supports Node.js versions 4.2 and higher.","status":"abandoned","version":"2.3.1","language":"javascript","source_language":"en","source_url":"git://github.com/1N50MN14/html-element","tags":["javascript","html-element","HTMLElement","element","shim"],"install":[{"cmd":"npm install html-element","lang":"bash","label":"npm"},{"cmd":"yarn add html-element","lang":"bash","label":"yarn"},{"cmd":"pnpm add html-element","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For non-global usage, import named exports directly since v2.","wrong":"const Element = require('html-element').Element;","symbol":"Element","correct":"import { Element } from 'html-element';"},{"note":"The 'document' object is exposed as a property of the main CommonJS export. It is not a named ESM export.","wrong":"import { document } from 'html-element';","symbol":"document","correct":"const document = require('html-element').document;"},{"note":"To restore v1 global behavior, explicitly require the global-shim since v2.0.0.","wrong":"require('html-element'); // In v2+, this does NOT create globals.","symbol":"Global Shim","correct":"require('html-element/global-shim'); // Creates global document, Element, etc."}],"quickstart":{"code":"const { document } = require('html-element');\n\nconst body = document.createElement('body');\nconst div = document.createElement('div');\ndiv.setAttribute('id', 'container');\ndiv.setAttribute('class', 'wrapper');\ndiv.textContent = 'Hello, html-element!';\n\nconst h1 = document.createElement('h1');\nh1.textContent = 'Page Title';\n\nbody.appendChild(h1);\nbody.appendChild(div);\n\nconst renderedHtml = body.toString();\nconsole.log(renderedHtml);\n/* Expected output:\n<body><h1>Page Title</h1><div id=\"container\" class=\"wrapper\">Hello, html-element!</div></body>\n*/","lang":"javascript","description":"Demonstrates basic usage of `html-element` to create a document, elements, set attributes and text content, then render to HTML string."},"warnings":[{"fix":"If you rely on global objects, change `require('html-element')` to `require('html-element/global-shim')`. For non-global usage, import objects directly: `const { document } = require('html-element');` or `import { Element } from 'html-element';`","message":"The package no longer affects the global namespace by default. `require('html-element')` will not create global `document` or `Element` objects.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Review code that sets properties expecting them to always reflect as HTML attributes. Use `setAttribute()` for explicit HTML attributes.","message":"Attribute handling was improved in v2.1.0 to distinguish more realistically between IDL (HTML properties like `htmlFor`) and Content attributes (HTML attributes like `for`). HTML output no longer reflects arbitrary properties into attributes.","severity":"breaking","affected_versions":">=2.1.0"},{"fix":"Ensure your Node.js environment is version 4.2 or newer.","message":"Node.js 4.2 LTS or higher is required. Older Node.js versions will not be supported.","severity":"gotcha","affected_versions":">=2.1.0"},{"fix":"No fix needed, but be aware of this behavior change if your code previously relied on `insertBefore(newNode, null)` *not* appending.","message":"`Node.insertBefore()` now correctly appends a new node if its `referenceNode` argument is `null`, aligning with DOM API specifications.","severity":"gotcha","affected_versions":">=2.2.0"},{"fix":"No fix needed, but be aware that setting `textContent` will overwrite existing child nodes.","message":"The `textContent` property can now be set on `Element` nodes, which removes all existing children and replaces them with a single text node.","severity":"gotcha","affected_versions":">=2.2.0"},{"fix":"Update any code that previously tried to infer the tag name from other properties or lacked this capability.","message":"`Element` instances now expose a `tagName` property, which returns the uppercase tag name of the element.","severity":"gotcha","affected_versions":">=2.2.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"If you need a global `document` object, change your import to `require('html-element/global-shim');`. Otherwise, import `document` explicitly: `const { document } = require('html-element');`","cause":"Attempting to access `document` global after upgrading from `html-element` v1 to v2 without adjusting import statements.","error":"ReferenceError: document is not defined"},{"fix":"Ensure you are accessing `document` correctly: `const { document } = require('html-element');` or `const document = require('html-element').document;`.","cause":"The main `html-element` export was `require()`d, but `document` was not accessed as a property, or the wrong import method was used for `document`.","error":"TypeError: Cannot read property 'createElement' of undefined"}],"ecosystem":"npm"}