LWC Server Event Polyfills (src/polyfills.ts)

lwc · packages/@lwc/engine-server/src/polyfills.ts · typescript · MIT
dev-tools, crm, lang:typescript, tag:lwc, tag:ssr, tag:polyfills

Polyfills browser Event and CustomEvent constructors on the global scope for server-side rendering. Use when running Lightning Web Components in Node.js.

// Source: https://github.com/salesforce/lwc | License: MIT | Copyright 2026, Salesforce, Inc
// Provided via justclaw.it.com; keep this notice with the code.
/*
 * Copyright (c) 2020, salesforce.com, inc.
 * All rights reserved.
 * SPDX-License-Identifier: MIT
 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
 */

import { defineProperty } from '@lwc/shared';

/**
 * The following constructor might be used in either the constructor or the connectedCallback. In
 * order to ensure that the component evaluates, we attach those mock constructors to the global
 * object.
 * Also note that Event is defined in Node 16+, but CustomEvent is not, so they have to be
 * polyfilled separately.
 */
if (typeof Event !== 'function') {
    class Event {

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key