GrapesJS/grapesjs · error
Parser code "${parserCode}" not found
Error message
Parser code "${parserCode}" not found What it means
ParserHtml's `__parseInput` lets callers supply a custom `parserCode` id that must be registered via `Parser.addParserCode`/parser registry. If a parser id is given but no parser with that code is registered, parsing cannot proceed and it throws.
Source
Thrown at packages/core/src/parser/model/ParserHtml.ts:487
res.html = resHtml;
Parser?.__emitEvent(ParserEvents.html, { input, output: res, options });
return res;
}
__getSyntheticNode(node: ParsedNodeMeta, opts: ParserHtmlInternalOptions) {
const parserConfig = this.em?.Parser?.getConfig() || this.config;
const SyntheticElement =
opts.__syntheticElementCtor || getSyntheticElementCtor(parserConfig.customSyntheticElement);
return new SyntheticElement(node);
}
__parseInput(input: string, options: HTMLParserOptions, cf: ParserConfig, parserCode: string) {
const codeParser = parserCode ? this.em?.Parser?.getParserCode(parserCode) : undefined;
const { asDocument } = options;
if (parserCode) {
if (!codeParser) throw new Error(`Parser code "${parserCode}" not found`);
const parsedNode = codeParser.parse(input, { editor: this.em?.getEditor()!, options });
const parsedNodes = isArray(parsedNode) ? parsedNode : [parsedNode];
return {
root: asDocument ? normalizeDocumentRoot(parsedNodes) : createFragmentRoot(parsedNodes),
isParsedMode: true,
};
}
const parseRes = isFunction(cf.parserHtml) ? cf.parserHtml(input, options) : BrowserParserHtml(input, options);
return {
root: asDocument
? domDocumentToParsedNode(parseRes as Document)
: domRootToFragmentParsedNode(parseRes as HTMLElement),
isParsedMode: false,
};View on GitHub (pinned to 2bdeda85b8)
Solutions
- Register the parser before use: `editor.Parser.addParserCode('myParser', myParser)`.
- Fix the parser id typo in the options/config.
- Remove the `parserCode` option if default parsing is sufficient.
- Ensure the plugin registering the parser loads before any `editor.setComponents`/parse call.
Example fix
// before
editor.setComponents(html, { parserCode: 'jsx' }); // 'jsx' never registered
// after
editor.Parser.addParserCode('jsx', jsxParser);
editor.setComponents(html, { parserCode: 'jsx' }); Defensive patterns
Strategy: validation
Validate before calling
const parserIds = ['html', 'css', 'myParser'];
for (const id of parserIds) {
if (!editor.Parser.getParserCode(id)) {
throw new Error(`Parser "${id}" must be registered via Parser.addParserCode before use`);
}
} Type guard
function hasParser(em, code) {
return Boolean(em?.Parser?.getParserCode?.(code));
} Try / catch
try {
editor.setComponents(html, { parserCode: 'myParser' });
} catch (err) {
if (err.message.startsWith('Parser code')) {
editor.Parser.addParserCode('myParser', myParser);
editor.setComponents(html, { parserCode: 'myParser' });
} else throw err;
} Prevention
- Register custom parsers in a plugin that loads before any parse/setComponents call
- Keep parser ids in a constant shared between registration and usage
- Verify parser support for your GrapesJS version (addParserCode API)
When it happens
Trigger: Parsing HTML with options like `{ parserCode: 'myParser' }` (or a component/model config referencing one) before registering that parser via `editor.Parser.addParserCode(id, parser)`; typos in the parser id; calling the internal `__parseInput` with an unregistered code.
Common situations: Custom HTML/JSX parsers set up in the wrong order (parse before plugin registration), misconfigured parser options, using a parser id from an old GrapesJS version after API changes.
Related errors
- Plugin ${explicitId} not found
- Target option is required
- Cannot modify immutable record
- Cannot remove immutable record
- 'container' is required
AI-assisted analysis of GrapesJS/grapesjs@2bdeda85b8 (2026-08-30).
Data as JSON: /api/errors/a0d71425549efacd.
Report an issue: GitHub.