TypeCellOS / BlockNote

A React Rich Text Editor that's block-based (Notion style) and extensible. Built on top of Prosemirror and Tiptap.
https://www.blocknotejs.org/
Mozilla Public License 2.0
6.69k stars 459 forks source link

document is not defined #919

Closed alfirus closed 3 months ago

alfirus commented 4 months ago

Describe the bug I'm using code from https://www.blocknotejs.org/docs/quickstart and place it inside my /app/departments/humanresource/memos/add.

When I try to "npm run build", i'll get

`Error occurred prerendering page "/departments/humanresource/memos/add". Read more: https://nextjs.org/docs/messages/prerender-error

ReferenceError: document is not defined`

To Reproduce This is my code `'use client'; import React, { useState } from 'react'; import UserData from '@/components/UserData'; import axios from 'axios'; import '@blocknote/core/fonts/inter.css'; import { useCreateBlockNote } from '@blocknote/react'; import { BlockNoteView } from '@blocknote/mantine'; import '@blocknote/mantine/style.css';

export default function MemoPage() { const editor = useCreateBlockNote();

const [memoTitle, setMemoTitle] = useState('');
const [html, setHtml] = useState('');

function add_memo() {
    axios
        .post(
            '/api/departments/humanresource/memos',
            {
                MemoTitle: memoTitle,
                MemoContent: html,
            },
            {
                headers: {
                    'Content-Type': 'application/json',
                },
            }
        )
        .then((response) => {
            if (response.status === 200) {
                window.location.href = '/departments/humanresource/memos?action=success';
            }
        })
        .catch((error) => {
            console.error(error);
        });
}

return (
    <UserData dep={'65b086a4192c48e28b29621d'}>
        <div className="container-fluid">
            <h1>[ ADD MEMO ]</h1>
            <div className="row">
                <div className="col">
                    <div className="card">
                        <div className="card-body">
                            <form id="addmemoform">
                                <div className="mb-3 row">
                                    <label className="col-sm-2 col-form-label">Title</label>
                                    <div className="col-sm-10">
                                        <input type="text" className="form-control" id="MemoTitle" onChange={(e) => setMemoTitle(e.target.value)} />
                                    </div>
                                </div>
                                <div className="mb-3 row">
                                    <div className="col">
                                        <BlockNoteView editor={editor} />
                                    </div>
                                </div>
                                <div className="row">
                                    <div className="col text-end">
                                        <button type="button" onClick={add_memo} className="btn btn-primary btn-sm">
                                            [ Add ]
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </UserData>
);

} `

Misc

YousefED commented 3 months ago

Please check https://www.blocknotejs.org/docs/advanced/nextjs :)

Aycom366 commented 2 months ago

my nextjs crashes anytime I run npm run build. my nextjs is 14.2.5 and I'm getting similar error.

Generating static pages (1/14) [= ]ReferenceError: document is not defined