question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

document is not defined

See original GitHub issue

Describe the bug

While all is working as expected 3.4.2, if I update to 3.5.6 I can’t render monaco editor properly


09:56:48.557 | > Build error occurred
-- | --
09:56:48.558 | ReferenceError: document is not defined
09:56:48.558 | at Object.<anonymous> (/vercel/19c883f1/node_modules/@monaco-editor/react/lib/utils/monaco.js:86:43)
09:56:48.558 | at Module._compile (internal/modules/cjs/loader.js:1156:30)
09:56:48.558 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
09:56:48.558 | at Module.load (internal/modules/cjs/loader.js:1000:32)
09:56:48.558 | at Function.Module._load (internal/modules/cjs/loader.js:899:14)
09:56:48.558 | at Module.require (internal/modules/cjs/loader.js:1042:19)
09:56:48.558 | at require (internal/modules/cjs/helpers.js:77:18)
09:56:48.558 | at Object.<anonymous> (/vercel/19c883f1/node_modules/@monaco-editor/react/lib/utils/index.js:47:38)
09:56:48.558 | at Module._compile (internal/modules/cjs/loader.js:1156:30)
09:56:48.558 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
09:56:48.558 | at Module.load (internal/modules/cjs/loader.js:1000:32)
09:56:48.558 | at Function.Module._load (internal/modules/cjs/loader.js:899:14)
09:56:48.558 | at Module.require (internal/modules/cjs/loader.js:1042:19)
09:56:48.558 | at require (internal/modules/cjs/helpers.js:77:18)
09:56:48.558 | at Object.<anonymous> (/vercel/19c883f1/node_modules/@monaco-editor/react/lib/Editor/Editor.js:22:14)
09:56:48.558 | at Module._compile (internal/modules/cjs/loader.js:1156:30)

This is how monaco is loaded from the code: https://github.com/microlinkhq/cards/blob/38f3bac85536de9caac9bb8d61f97d136bb45a60/packages/app/src/components/live-editor.js#L74

To Reproduce

https://github.com/microlinkhq/cards/pull/87

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Kikobeatscommented, Aug 9, 2020

hey 3.5.7 is working fine! 🙂

0reactions
suren-atoyancommented, Aug 9, 2020

Hi @Kikobeats,

The problem was Next.js, it doesn’t “accept” document in server-side rendering. There are many issues out there about that. I’ve just modified my functions a little bit to avoid interacting with document during lazy parsing.

Please, check the new version - v3.5.7 Let me know if it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: document is not defined (in plain JavaScript)
Explanation: The error is caused because NextJs renders the page in the server only and in the server document (document is used inside...
Read more >
ReferenceError: document is not defined in JavaScript
The "ReferenceError: document is not defined" error occurs for multiple reasons: ... The document relates to the document object which represents a web...
Read more >
ReferenceError: document is not defined in JavaScript
The "ReferenceError: document is not defined" error is thrown when the code tries to access the document object, but the object is not ......
Read more >
How to fix ReferenceError: Document is not defined ... - Sabe.io
The most common reason for getting the reference error while on the browser is when you try to access the document object too...
Read more >
How to solve the document is not defined error - Flavio Copes
Here's how to fix the “referenceerror: document is not defined” error that you might have in Node.js or with a tool like Next.js....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found