Node ssr module ReferenceError:

Discussão em 'Angular' iniciado por Desperado, Janeiro 17, 2025.

  1. Desperado

    Desperado Guest

    I am new to Node so I'm not sure what is happening with my SSR code.
    One of the imported modules uses MutationObserver which I though I could handle by defining a shim for this class inside another module which I import before the problematic module.

    Something like this should work I thought:

    import './app/server-rendering';
    import {render} from '../packages/lit-labs-ssr'; // <-- module that uses MutationObserver


    server-rendering.ts:

    // @ts-ignore: Override the global MutationObserver in SSR
    class MutationObserver {
    observe() {
    // No-op in SSR
    }

    disconnect() {
    // No-op in SSR
    }

    takeRecords() {
    // No-op in SSR
    return [];
    }
    }

    // @ts-ignore: Override the global MutationObserver in SSR
    global.MutationObserver = MutationObserver;


    Could someone please explain why this doesn't work.

    Error:

    12:27:53 AM [vite] Error when evaluating SSR module /@fs/C:/Users/illus/VSProjects/SluzbeniList/AngularApp/.angular/cache/19.0.7/AngularApp/vite/deps_ssr/chunk-QVHPIT5W.js?v=a381c8e8:
    |- ReferenceError: MutationObserver is not defined
    at eval (C:\Users\illus\VSProjects\SluzbeniList\AngularApp\.angular\cache\19.0.7\AngularApp\vite\deps_ssr\chunk-QVHPIT5W.js:27:19)
    at async instantiateModule (file:///C:/Users/illus/VSProjects/SluzbeniList/AngularApp/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:52972:5)

    Continue reading...

Compartilhe esta Página