Skip to content

ReferenceError: document is not defined #1624

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

Closed
fiderosado opened this issue Apr 22, 2025 · 16 comments
Closed

ReferenceError: document is not defined #1624

fiderosado opened this issue Apr 22, 2025 · 16 comments
Labels
bug Something isn't working

Comments

@fiderosado
Copy link

I have been receiving constant console errors referring to this particular error:

 ⨯ ReferenceError: document is not defined
    at eval (file://D%3A/GitHub/test_blocknote/components/editor/businessBlockNoteEditor.js:69:31)
    at BusinessBlockNoteEditor (file://D%3A/GitHub/test_blocknote/components/editor/businessBlockNoteEditor.js:65:27)
  67 |             return undefined;
  68 |         }
> 69 |         return BlockNoteEditor.create({
     |                               ^
  70 |             initialContent,
  71 |             uploadFile,
  72 |             codeBlock, {
  digest: '1549453249'
}
@fiderosado fiderosado added the bug Something isn't working label Apr 22, 2025
@nperez0111
Copy link
Contributor

document not being defined makes me think you are running this on the server instead of the browser.

Also strange that you are eval-ing this code

@fiderosado
Copy link
Author

At this moment the component is on the client side, "use client", I don't understand the error, I have tried several methods but it always shows me the error

@nperez0111
Copy link
Contributor

The document would be defined if it were running on the client. So you may have something set up incorrectly in your application.

Given blocknote is working for everyone else, it is likely an issue in your application

@fiderosado
Copy link
Author

I just deleted the .next folder to evaluate the error, deleting the project cache.

@nperez0111
Copy link
Contributor

See this for more information on use client https://react.dev/reference/rsc/use-client

@nperez0111
Copy link
Contributor

I just deleted the .next folder to evaluate the error, deleting the project cache.

And, did that resolve it?

@fiderosado
Copy link
Author

the error persists, I have deleted the entire component and put it as in the documentation
⨯ ReferenceError: document is not defined

65 | const editor = BlockNoteEditor.create({

@nperez0111
Copy link
Contributor

Sorry, but this is an issue of your application. I can't really help you further than this.

If you do a console.log before trying to instantiate the editor (BlockNoteEditor.create), it will log on the server. If I'm wrong, and it logs on the client, then we can re-open and look into this further

@fiderosado
Copy link
Author

I created a new page with the component. In server mode, I get the following error:

⨯ TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component

@fiderosado
Copy link
Author

On the client side I have the following error:

Yjs was already imported. This breaks constructor checks and will lead to issues! - yjs/yjs#438
⨯ ReferenceError: document is not defined
at PageTest (file://D%3A/GitHub/block_note_test/app/test/page.jsx:9:36)
7 | export default function PageTest(){
8 | // Creates a new editor instance.

9 | const editor = useCreateBlockNote();
| ^
10 |
11 | // Renders the editor instance using a React component.
12 | return ; {
digest: '3223823464'
}

@fiderosado
Copy link
Author

In BlockNoteEditor.ts I have seen that it is import * as Y from "yjs";, maybe this is the problem

@nperez0111
Copy link
Contributor

You are having issues with client vs. server components. This has nothing to do with BlockNote. You'll have to solve this for yourself

@fiderosado
Copy link
Author

I'm working on it, but I don't understand the Blocknote component. I only use it on the client side because it uses a library that breaks the constructor.

@fiderosado
Copy link
Author

I found 18 imports of the yjs module, does it look familiar to you?

@nperez0111
Copy link
Contributor

STOP MESSAGING ME
This is your problem to solve

@fiderosado
Copy link
Author

This is a public thread, it is not directed only to you but to anyone who has knowledge of the subject, feel free to respond or simply skip, any response to the thread is appreciated

@TypeCellOS TypeCellOS locked as off-topic and limited conversation to collaborators Apr 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants