Studyyyyy
next js 16 import toast ui editor("Element is not defined" 오류) 본문
Nextjs/App router
next js 16 import toast ui editor("Element is not defined" 오류)
manyYun 2025. 11. 17. 16:03Next.js 16(=App Router) + Toast UI Editor(브라우저 전용 라이브러리)
→ 서버 컴포넌트 환경에서 렌더링
→ window, document, Element 같은 브라우저 객체를 참조
→ Element is not defined 오류 발생.
때문에 클라이언트 전용(import 시점 지연)으로 로딩해야 오류가 나지 않는다.
Toast UI Editor는 SSR에서 바로 사용할 수 없기 때문에 Next.js 16에서는 동적 import + ssr: false 조합이 필수
1. dynamic import 할 컴포넌트 생성
import { Editor, EditorProps } from "@toast-ui/react-editor";
import React from "react";
const DynamicEditor = ({ ...rest }: EditorProps) => {
return <Editor {...rest} />;
};
export default DynamicEditor;
2. dynamic import에서 ssr false 설정
const DynamicEditor = dynamic(() => import("@/components/common/DynamicEditor"), {
ssr: false,
loading: () => <div>Loading...</div>,
});
...
<DynamicEditor
initialValue=""
previewStyle="vertical"
height="300px"
initialEditType="wysiwyg"
useCommandShortcut={true}
/>
참조: https://velog.io/@chosh91/Nextjs-Nextjs-14%EB%B2%84%EC%A0%84-ToastUI-Editor-error
'Nextjs > App router' 카테고리의 다른 글
| 페이지 전환 시 Suspense의 fallback이 나타나지 않는 현상 (0) | 2025.09.09 |
|---|---|
| 클라이언트의 router.push()를 사용했을 때 middleware가 작동하지 않는 현상 (0) | 2025.06.05 |
| React-tooltip (0) | 2025.03.14 |
| Next js 15 + Next auth + Cognito 로 로그인/회원가입 구현하기 (0) | 2025.02.28 |
| Server component 와 CSS-in-JS (0) | 2025.01.21 |