ueberdosis/tiptap · error
generateJSON can only be used in a browser environment If yo
Error message
generateJSON can only be used in a browser environment If you want to use this in a Node environment, use the `@tiptap/html/server` import instead.
What it means
Error "generateJSON can only be used in a browser environment If you want to use this in a Node environment, use the `@tiptap/html/server` import instead." thrown in ueberdosis/tiptap.
Source
Thrown at packages/html/src/generateJSON.ts:24
/**
* Generates a JSON object from the given HTML string and converts it into a Prosemirror node with content.
* @param {string} html - The HTML string to be converted into a Prosemirror node.
* @param {Extensions} extensions - The extensions to be used for generating the schema.
* @param {ParseOptions} options - The options to be supplied to the parser.
* @returns {Record<string, any>} - The generated JSON object.
* @example
* const html = '<p>Hello, world!</p>'
* const extensions = [...]
* const json = generateJSON(html, extensions)
* console.log(json) // { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }] }] }
*/
export function generateJSON(
html: string,
extensions: Extensions,
options?: ParseOptions,
): Record<string, any> {
if (typeof window === 'undefined') {
throw new Error(
'generateJSON can only be used in a browser environment\nIf you want to use this in a Node environment, use the `@tiptap/html/server` import instead.',
)
}
const schema = getSchema(extensions)
const doc: Document = new window.DOMParser().parseFromString(html, 'text/html')
if (!doc) {
throw new Error('Failed to parse HTML string')
}
return DOMParser.fromSchema(schema)
.parse(doc.body as Node, options)
.toJSON()
}
View on GitHub (pinned to 496d53afd7)
When it happens
Trigger: Thrown at packages/html/src/generateJSON.ts:24 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ueberdosis/tiptap@496d53afd7 (2026-08-26).
Data as JSON: /api/errors/48b9d02a6a02ad70.
Report an issue: GitHub.