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

document is not defined #292

Closed
andylacko opened this issue Nov 21, 2017 · 21 comments
Closed

document is not defined #292

andylacko opened this issue Nov 21, 2017 · 21 comments

Comments

@andylacko
Copy link

image

@alexkrolick
Copy link
Collaborator

Are you server-side rendering? #185

@andylacko
Copy link
Author

I am using nextjs, so yes

@alexkrolick
Copy link
Collaborator

OK, #185 should contain everything you need 😄

@AryanJ-NYC
Copy link

If you're stumbling upon this, go straight to #122 instead of #185. #185 just forwards you to #122.

@sshekhar336
Copy link

Hi,
Add { ssr: false } to stop server side rendering in dynamic import.

@ashisdeveloper
Copy link

const ReactQuill = typeof window === 'object' ? require('react-quill') : () => false;

// Use ReactQuill as desired

@MuhammadMinhaj
Copy link

MuhammadMinhaj commented Mar 2, 2022

In NextJS, you can use dynamic import to disable server-side rendering to fix this issue.
For example -
const ReactQuill = dynamic(() => import('react-quill'), { ssr: false });

Thanks

@rhinehardtc
Copy link

Don't forget to import dynamic from 'next/dynamic' like I did for MuhammadMinhaj's answer to work!

@ninsau
Copy link

ninsau commented Jul 4, 2022

In NextJS, you can use dynamic import to disable server-side rendering to fix this issue. For example - const ReactQuill = dynamic(() => import('react-quill'), { ssr: false });

Thanks

thanks! this works

@Coder-Devesh-Agarwal
Copy link

React Quill Rendering Twice ??

@cornnnnnnnnnnnnnnnn
Copy link

1665988586250
how to fix it?

@Saravanakumarkandasamy
Copy link

const ReactQuill = dynamic(import('react-quill'), { ssr: false})
Try This.

@MiguelMarroquin
Copy link

I made a component for the quill editor and render it dynamic , and client side.

"use client";
import dynamic from "next/dynamic";
const ReactQuill = dynamic(() => import("react-quill"), { ssr: false });

import "react-quill/dist/quill.bubble.css";

function TextEditor({ value, name, handleQuillChange, label }) {
	return (
		<div className='flex flex-col mt-3'>
			<p className='mt-4 text-sm font-medium'>{label}</p>
			<ReactQuill
				className=' mt-1 px-2 rounded-xl border hover:scale-105 duration-300'
				value={value}
				onChange={handleQuillChange(name)}
				theme='bubble'
			/>
		</div>
	);
}

export default TextEditor;

Then I import it on a form that is rendered also "use client"

but I have this error:

ReferenceError: document is not defined
    at Object.eval (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:7656:12)
    at __nested_webpack_require_697__ (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:31:30)
    at Object.eval (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:1025:1)
    at __nested_webpack_require_697__ (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:31:30)
    at Object.eval (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:5650:14)
    at __nested_webpack_require_697__ (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:31:30)
    at Object.eval (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:10040:13)
    at __nested_webpack_require_697__ (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:319:20)
    at eval (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:11:3)
    at (sc_client)/./node_modules/quill/dist/quill.js (D:\Coding\NEXTJS\jjudit_nextjs13\.next\server\_sc_client_node_modules_react-quill_lib_index_js.js:909:1)
    at __webpack_require__ (D:\Coding\NEXTJS\jjudit_nextjs13\.next\server\webpack-runtime.js:33:43)
    at eval (webpack-internal:///(sc_client)/./node_modules/react-quill/lib/index.js:43:31)
    at (sc_client)/./node_modules/react-quill/lib/index.js (D:\Coding\NEXTJS\jjudit_nextjs13\.next\server\_sc_client_node_modules_react-quill_lib_index_js.js:920:1)
    at __webpack_require__ (D:\Coding\NEXTJS\jjudit_nextjs13\.next\server\webpack-runtime.js:33:43)
    at __webpack_require__.t (D:\Coding\NEXTJS\jjudit_nextjs13\.next\server\webpack-runtime.js:73:38)           at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

@jjmss
Copy link

jjmss commented Feb 1, 2023

const ReactQuill = dynamic(import('react-quill'), { ssr: false}) Try This.

Wrapping the import within useMemo solved the issue for me (source: https://stackoverflow.com/a/74096771/12103912)

@LeeManh
Copy link

LeeManh commented Apr 26, 2023

const ReactQuill = typeof window === 'object' ? require('react-quill') : () => false;

Tks. I work for me

@0xMazout
Copy link

I made a component for the quill editor and render it dynamic , and client side.

"use client";
import dynamic from "next/dynamic";
const ReactQuill = dynamic(() => import("react-quill"), { ssr: false });

import "react-quill/dist/quill.bubble.css";

function TextEditor({ value, name, handleQuillChange, label }) {
	return (
		<div className='flex flex-col mt-3'>
			<p className='mt-4 text-sm font-medium'>{label}</p>
			<ReactQuill
				className=' mt-1 px-2 rounded-xl border hover:scale-105 duration-300'
				value={value}
				onChange={handleQuillChange(name)}
				theme='bubble'
			/>
		</div>
	);
}

export default TextEditor;

Then I import it on a form that is rendered also "use client"

but I have this error:

ReferenceError: document is not defined
    at Object.eval (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:7656:12)
    at __nested_webpack_require_697__ (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:31:30)
    at Object.eval (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:1025:1)
    at __nested_webpack_require_697__ (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:31:30)
    at Object.eval (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:5650:14)
    at __nested_webpack_require_697__ (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:31:30)
    at Object.eval (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:10040:13)
    at __nested_webpack_require_697__ (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:319:20)
    at eval (webpack-internal:///(sc_client)/./node_modules/quill/dist/quill.js:11:3)
    at (sc_client)/./node_modules/quill/dist/quill.js (D:\Coding\NEXTJS\jjudit_nextjs13\.next\server\_sc_client_node_modules_react-quill_lib_index_js.js:909:1)
    at __webpack_require__ (D:\Coding\NEXTJS\jjudit_nextjs13\.next\server\webpack-runtime.js:33:43)
    at eval (webpack-internal:///(sc_client)/./node_modules/react-quill/lib/index.js:43:31)
    at (sc_client)/./node_modules/react-quill/lib/index.js (D:\Coding\NEXTJS\jjudit_nextjs13\.next\server\_sc_client_node_modules_react-quill_lib_index_js.js:920:1)
    at __webpack_require__ (D:\Coding\NEXTJS\jjudit_nextjs13\.next\server\webpack-runtime.js:33:43)
    at __webpack_require__.t (D:\Coding\NEXTJS\jjudit_nextjs13\.next\server\webpack-runtime.js:73:38)           at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I Have the same problem if someone can help

@MammadProMax
Copy link

make sure include "use client" at the top of the file

@tajkir-alam
Copy link

const ReactQuill = useMemo(() => dynamic(() => import('react-quill'), { ssr: false }),[]);

this helped me. don't forget to use 'useMemo' it will store the data otherwise it will render. and obviously, write the code inside of your react function component.

@yogithesymbian
Copy link

const ReactQuill = dynamic(() => import('react-quill'), { ssr: false });

greats work like a charm

@ABEL-Dion
Copy link

const ReactQuill = typeof window === 'object' ? require('react-quill') : () => false;

// Use ReactQuill as desired

@ABEL-Dion
Copy link

It worked perfectly Thank you

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