Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"window is not defined" in NextJS. #376

Open
rangicus opened this issue Dec 11, 2023 · 4 comments · May be fixed by #401
Open

"window is not defined" in NextJS. #376

rangicus opened this issue Dec 11, 2023 · 4 comments · May be fixed by #401

Comments

@rangicus
Copy link

rangicus commented Dec 11, 2023

Next Version: 13.5.2
Unlayer Version: 1.7.9

Log:

node_modules/react-email-editor/dist/react-email-editor.cjs.development.js (140:0) @ eval
ReferenceError: window is not defined
at webpack_require (/opt/noc/.next/server/webpack-runtime.js:33:43)
at webpack_require (/opt/noc/.next/server/webpack-runtime.js:33:43)
at eval (./app/email/reply/[uuid]/page.tsx:9:76)
at (ssr)/./app/email/reply/[uuid]/page.tsx (/opt/noc/.next/server/app/email/reply/[uuid]/page.js:227:1)
at webpack_require (/opt/noc/.next/server/webpack-runtime.js:33:43)

Relevant Code:

"use client";

// Imports

import React, { Fragment, useRef, useState } from "react";
import { EditorRef, EmailEditor } from "react-email-editor";


// Main Component

export default function EmailRenderer () {
	// References

    const emailEditorRef = useRef<EditorRef>(null);

	// Rendering

	return (
          <div className="container">
            {/* Response */}
            <h2>Response Builder</h2>
            <Fragment>
              <EmailEditor
                ref={emailEditorRef}
                onReady={(unlayer) => {
                  unlayer.loadDesign({
                  counters: {},
                  body: {
                    id: undefined,
                    rows: [], headers: [], footers: [],
                    values: {
                      backgroundColor: `#ffffff`,
                    },
                  }
                  });
               }}
              />
            </Fragment>
          </div>
	);
}
@arndvs
Copy link

arndvs commented Dec 12, 2023

I'm having the same issue. Tried backign it down to 1.7.8 and 1.7.7

@awalton3
Copy link

awalton3 commented Jan 23, 2024

I am seeing the same issue. I fixed it by doing a dynamic import (read more here):

const DesignEditor = dynamic( () => { return import("./edit-design-view"); }, { ssr: false } );

But when doing the above code, the save and export functionality of the editor doesn't work :( Any help would be great.

@awalton3
Copy link

UPDATE: downgrading to 1.7.7 worked for me. I am using next: 14.0.4

@notrapha
Copy link

I had the same issue, editor was not working well with dynamic.
I solved it with: https://stackoverflow.com/questions/77020572/correct-way-to-use-forwardref-and-next-dynamic-in-next-js-13-4-for-react-email

const emailEditorRef = useRef<EditorRef | null>(null)

const onReady: EmailEditorProps['onReady'] = (editor) => {
    emailEditorRef.current = { editor }
}

<EmailEditor
    ref={emailEditorRef}
    onLoad={onLoad}
    onReady={onReady}
    minHeight={1024}
    />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants