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.

slate-html-serializer + nextjs issue with server side rendering

See original GitHub issue

Do you want to request a feature or report a bug?

Report a bug

What’s the current behavior?

Step to reproduce the bug: Create a nextJS project

 npx create-next-app

Install slate

npm install -save slate
npm install -save slate-html-serializer
# for some reason immutable is required
npm install -save immutable

Create a component using slate-html-serialize based on that tutoriel: https://docs.slatejs.org/walkthroughs/saving-and-loading-html-content

Get this error

Error: The native `DOMParser` global which the `Html` serializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead.

Then import jsdom as explained in the documentation

npm install -save jsdom

Use it

const html = new Html({ rules,parseHtml: JSDOM.fragment })

Get this error (I guess it’s related to server-side rendering)

compiling ...
[ error ] ./node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js
Module not found: Can't resolve 'child_process' in '/home/venom/w/slate-nextjs/node_modules/jsdom/lib/jsdom/living'
ModuleNotFoundError: Module not found: Error: Can't resolve 'child_process' in '/home/venom/w/slate-nextjs/node_modules/jsdom/lib/jsdom/living'
    at factory.create (/home/venom/w/slate-nextjs/node_modules/webpack/lib/Compilation.js:888:10)
    at factory (/home/venom/w/slate-nextjs/node_modules/webpack/lib/NormalModuleFactory.js:401:22)
    at resolver (/home/venom/w/slate-nextjs/node_modules/webpack/lib/NormalModuleFactory.js:130:21)
    at asyncLib.parallel (/home/venom/w/slate-nextjs/node_modules/webpack/lib/NormalModuleFactory.js:224:22)
    at /home/venom/w/slate-nextjs/node_modules/neo-async/async.js:2830:7
    at /home/venom/w/slate-nextjs/node_modules/neo-async/async.js:6877:13
    at normalResolver.resolve (/home/venom/w/slate-nextjs/node_modules/webpack/lib/NormalModuleFactory.js:214:25)
    at doResolve (/home/venom/w/slate-nextjs/node_modules/enhanced-resolve/lib/Resolver.js:184:12)
    at hook.callAsync (/home/venom/w/slate-nextjs/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/home/venom/w/slate-nextjs/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at resolver.doResolve (/home/venom/w/slate-nextjs/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:37:5)
    at hook.callAsync (/home/venom/w/slate-nextjs/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/home/venom/w/slate-nextjs/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at hook.callAsync (/home/venom/w/slate-nextjs/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/home/venom/w/slate-nextjs/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
    at resolver.doResolve (/home/venom/w/slate-nextjs/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:42:38)

Side note

I built a simple public repository so you guys can have a look at the code: https://github.com/we-are-venom/slate-nextjs/

The editor: https://github.com/we-are-venom/slate-nextjs/blob/master/components/rich-editor.js

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
minimaluminiumcommented, Oct 7, 2019

Happened to me recently. I ended up loading the component only on the client side.

const Editor = dynamic(() => import('../../components/Editor'), {
  ssr: false
})
0reactions
ianstormtaylorcommented, Nov 28, 2019

As of https://github.com/ianstormtaylor/slate/pull/3093 (which was just merged), I believe this issue is no longer applicable, because a lot has changed. I’m going through and closing out any potential issues that are not out of date with the overhaul. Thanks for understanding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

slate-html-serializer
The HTML serializer lets you parse and stringify arbitrary HTML content, based on your specific schema's use case. You must pass a series...
Read more >
What is Slate.js, and will it replace Quill and Draft.js?
Slate.js makes serialization to HTML, Markdown, and other formats possible. Simple tasks like converting a document to HTML or Markdown is made ...
Read more >
Welcome to Everything.js | Everything.js
prerender/prerender - Node server that uses Headless Chrome to render a javascript-rendered page as HTML. To be used in conjunction with prerender middleware....
Read more >
Web-Programming-for-Apps-and-Services.pdf
Fetching API Data for Pre-Rendered HTML ... If you create a server-based program, and it is intended to be used ... "blank slate"...
Read more >
slate-html-serializer
An HTML serializer for Slate editors.. Latest version: 0.8.13, last published: 3 years ago. Start using slate-html-serializer in your ...
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