Skip to content

[Bug]: Internal server error: DOMMatrix is not defined #19847

Answered by jpetersam
jpetersam asked this question in Q&A
Discussion options

You must be logged in to vote

I'm running locally and my start is "react-router dev". I agree with @petero-dk that I am performing server-side rendering as the window object is not available at the time I was doing the import.

To resolve this, I dynamically imported the library when the component function is being executed. It looks roughly as follows:

// Define PDFJS...
let pdfjs: any | null = null;

/**
 * The document view.
 * 
 * @returns The document view.
 */
const DocumentView = (props: any) =>
{
    if (typeof window !== 'undefined')
    {
        // Import PDF.js...
        import("pdfjs-dist").then((pdfjsObject) =>
        {
            pdfjs = pdfjsObject;

            // Set the worker source...
          …

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jpetersam
Comment options

Answer selected by jpetersam
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #19846 on April 23, 2025 06:37.