tiptap: [Bug]: dynamic usage of require is not supported
Affected Packages
html
Version(s)
3.0.0-beta.7
Bug Description
In Next.js server functions
If I use Next.js with Turbopack
When I call the generateHTML function or the generateJSON function
This error is thrown:
Error: dynamic usage of require is not supported
Browser Used
Chrome
Code Example URL
No response
Expected Behavior
The error is not thrown
Additional Context (Optional)
I think the error is due to this dynamic require call:
I think the dynamic require is made on purpose so that the happy-dom-without-node library is not loaded in the browser. But then how do we make it work with Next.js?
Dependency Updates
- Yes, I’ve updated all my dependencies.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 2
- Comments: 24 (12 by maintainers)
I will check again if there’s no other way except making it async (for example another happy-dom package that doesn’t nuke node internals lol).
Last resort will probably be a breaking change with async/await syntax
I think this is the issue https://github.com/vercel/next.js/issues/56531
A possible solution would be to use
importinstead ofrequire, the downside is that this would make thegenerateHTMLandgenerateJSONfunctions async.This separation of server and non-server
generateJSONimplementations is proving to be a big PITA.Refactored/duplicated already dozens of files and there seemingly is no end to how deeply this is going to go.
@bdbch why does
/serverentry still using dynamic import if now it is dedicated to server?This seems to unnecessarily turn the function to async.
Okay I’m working on it right now - doing my final tests.
Current implementation looks like this - the default
@tiptap/htmlimport will only be used for client side environments where window and the browser API is accessible. That way we won’t need any happy-dom that mocks NodeJS API’s.There will be an additional, code-splittable import
@tiptap/html/serverthat will provide async packages which will lazyloadhappy-domon demand.I’m doing local node tests now. Will come back later.
As reported here (with a reproduction example), this is happening in both cases where the turbopack is enabled and disabled. So, it’s not a turbopack issue: https://github.com/ueberdosis/tiptap/issues/6502
Making it async is a pretty reasonable option in my opinion. That way, we should be able to use
generateHTMLwith NextJS async (server) components.I am getting same error with Vite/Rollup.