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

error "node_modules/@editorjs/editorjs/dist/editorjs.umd.js (1:525) @ eval" and "ReferenceError: Element is not defined" #2492

Open
hozaifa4you opened this issue Sep 23, 2023 · 2 comments

Comments

@hozaifa4you
Copy link

The question.

I am facing an error like on terminal.

- error node_modules/@editorjs/editorjs/dist/editorjs.umd.js (1:525) @ eval
- error ReferenceError: Element is not defined
    at __webpack_require__ (/home/yousuf4you/Desktop/devto-clone/.next/server/webpack-runtime.js:33:43)
    at eval (./components/ContentEditor.tsx:9:76)
    at (ssr)/./components/ContentEditor.tsx (/home/yousuf4you/Desktop/devto-clone/.next/server/app/posts/new/page.js:10975:1)
    at __webpack_require__ (/home/yousuf4you/Desktop/devto-clone/.next/server/webpack-runtime.js:33:43)
    at eval (./app/posts/new/page.tsx:18:83)
    at (ssr)/./app/posts/new/page.tsx (/home/yousuf4you/Desktop/devto-clone/.next/server/app/posts/new/page.js:10964:1)
    at __webpack_require__ (/home/yousuf4you/Desktop/devto-clone/.next/server/webpack-runtime.js:33:43)

and my code is:

"use client";
import React, { Dispatch, SetStateAction, useEffect } from "react";
import EditorJS, { OutputData } from "@editorjs/editorjs";
import Header from "@editorjs/header";
import LinkTool from "@editorjs/link";
import RawHTML from "@editorjs/raw";
import CheckList from "@editorjs/checklist";
import SimpleImage from "@editorjs/simple-image";
import Embed from "@editorjs/embed";
import Quote from "@editorjs/quote";
import Paragraph from "@editorjs/paragraph";
import Table from "@editorjs/table";
import NestedList from "@editorjs/nested-list";
import TextVariantTune from "@editorjs/text-variant-tune";
import Underline from "@editorjs/underline";
import InlineCode from "@editorjs/inline-code";
import CodeTool from "@editorjs/code";
import Warning from "@editorjs/warning";
import Marker from "@editorjs/marker";
import AttachesTool from "@editorjs/attaches";
import Delimiter from "@editorjs/delimiter";

interface PropTypes {
  setOutputData: Dispatch<SetStateAction<OutputData | null>>;
}

const ContentEditor = ({ setOutputData }: PropTypes) => {
  useEffect(() => {
    const editor = new EditorJS({
      holder: "editorjs",
      placeholder: "Write your post content here...",
      // onReady: () => {
      //   editorRef.current = editor;
      // },
      onChange: async () => {
        const content = await editor.saver.save();
        setOutputData(content);
      },

      tools: {
        header: { class: Header, inlineToolbar: true },
        list: { class: NestedList, inlineToolbar: true },
        checklist: {
          class: CheckList,
          inlineToolbar: true,
        },
        // FIXME: some fix need
        linkTool: {
          class: LinkTool,
        },
        rawHtml: RawHTML,
        image: {
          class: SimpleImage,
          inlineToolbar: true,
          config: {
            placeholder: "Paste image URL",
          },
        },
        embed: {
          class: Embed,
          config: {
            service: {
              youtube: true,
              facebook: true,
              instagram: true,
              twitter: true,
              codepen: true,
              pinterest: true,
            },
          },
        },
        quote: {
          class: Quote,
          inlineToolbar: true,
          shortcut: "CMD+SHIFT+O",
          config: {
            quotePlaceholder: "Enter a quote",
            captionPlaceholder: "Quote's author",
          },
        },
        paragraph: {
          class: Paragraph,
          inlineToolbar: true,
        },
        table: {
          class: Table,
          inlineToolbar: true,
          config: {
            rows: 2,
            cols: 3,
          },
        },
        textVariant: TextVariantTune,
        underline: Underline,
        inlineCode: {
          class: InlineCode,
          shortcut: "CMD+SHIFT+M",
        },
        code: CodeTool,
        warning: {
          class: Warning,
          inlineToolbar: true,
          shortcut: "CMD+SHIFT+W",
          config: {
            titlePlaceholder: "Title",
            messagePlaceholder: "Message",
          },
        },
        Marker: {
          class: Marker,
          shortcut: "CMD+SHIFT+M",
        },
        attaches: {
          class: AttachesTool,
          config: {
            // FIXME: fix the path
            endpoint: "http:https://localhost:8008/uploadFile",
          },
        },
        delimiter: Delimiter,
      },
    });

    return () => {
      editor.destroy();
    };
  }, [setOutputData]);

  return <div id="editorjs"></div>;
};

export default ContentEditor;

I'm using

OS: [email protected] LTS
Runtime: [email protected]
NextJs: 13.4.19
Typescript: 5.2.2

Hope someone will solve the problem.

@hozaifa4you hozaifa4you changed the title error "node_modules/@editorjs/editorjs/dist/editorjs.umd.js (1:525) @ eval" and "node_modules/@editorjs/editorjs/dist/editorjs.umd.js (1:525) @ eval" error "node_modules/@editorjs/editorjs/dist/editorjs.umd.js (1:525) @ eval" and "ReferenceError: Element is not defined" Sep 23, 2023
@TD-INFRANFC
Copy link

+1 same problem

@limichange
Copy link

You need to dynamically load the component and disable ssr.

import dynamic from 'next/dynamic'

export const EditorJS = dynamic(() => import('./EditorJSInner'), {
  ssr: false,
})

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

No branches or pull requests

3 participants