mac-s-g / react-json-view

JSON viewer for react
https://mac-s-g.github.io/react-json-view/demo/dist/
MIT License
3.42k stars 530 forks source link

ReferenceError: document is not defined #460

Closed khot-aditya closed 2 months ago

khot-aditya commented 2 months ago

I am using @microlink/react-json-view 1.23.1 with Next.js 14 in client component and facing document is not defined error. Looking for suggestions to resolve this. FYI: This error is only in terminal and UI is working properly.

 ✓ Compiled in 1504ms (820 modules)
 ⨯ node_modules/@microlink/react-json-view/dist/main.js (1:82281) @ Module.eval
 ⨯ ReferenceError: document is not defined
    at __webpack_require__ (/home/aditya/workspace/khot-aditya/next-cms-app-2/.next/server/webpack-runtime.js:33:42)
    at eval (./src/app/admin/page.tsx:11:84)
    at (ssr)/./src/app/admin/page.tsx (/home/aditya/workspace/khot-aditya/next-cms-app-2/.next/server/app/admin/page.js:282:1)
    at __webpack_require__ (/home/aditya/workspace/khot-aditya/next-cms-app-2/.next/server/webpack-runtime.js:33:42)
    at JSON.parse (<anonymous>)
null

image

khot-aditya commented 2 months ago

Found the solution:

import dynamic from "next/dynamic";

const ReactJson = dynamic(() => import("@microlink/react-json-view"), {
  ssr: false,
});