{"record":{"id":"21aca0faab5ad292","repo":"facebook/lexical","slug":"codehighlightplugin-codenode-or-codehighlightnode-21aca0","errorCode":null,"errorMessage":"CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor","messagePattern":"CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/lexical-code-shiki/src/CodeHighlighterShiki.ts","lineNumber":453,"sourceCode":"      $textNodeTransform.bind(null, editor, tokenizer, transformState),\n    ),\n  );\n\n  return mergeRegister(...registrations);\n}\n\n/**\n * Register the Shiki tokenizer-driven highlighting on the editor along\n * with the indent / Tab / arrow-key keyboard handlers. This function\n * is provided for legacy code that has not upgraded to using\n * {@link CodeShikiExtension}.\n */\nexport function registerCodeHighlighting(\n  editor: LexicalEditor,\n  tokenizer: Tokenizer = ShikiTokenizer,\n): () => void {\n  if (!editor.hasNodes([CodeNode, CodeHighlightNode])) {\n    throw new Error(\n      'CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor',\n    );\n  }\n  return mergeRegister(\n    registerHighlightingOnly(editor, tokenizer),\n    registerCodeIndentation(editor),\n  );\n}\n\nexport interface CodeShikiConfig {\n  /**\n   * When true, the Shiki code highlighter is not registered on the editor.\n   * This signal can be flipped at runtime to enable or disable the\n   * highlighter, for example to switch between the Prism and Shiki\n   * highlighters without rebuilding the editor.\n   */\n  disabled: boolean;\n  tokenizer: Tokenizer;","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/facebook/lexical/blob/76a22dcba981b46119fcec45f935270707e26a57/packages/lexical-code-shiki/src/CodeHighlighterShiki.ts#L435-L471","documentation":"registerCodeHighlighting() in @lexical/code-shiki throws when the editor has not registered CodeNode and CodeHighlightNode, since Shiki-based highlighting decorates and transforms those node classes. Lexical requires every node type the code touches to be present in the editor's node config. The check runs at registration so the failure surfaces immediately rather than during a keystroke.","triggerScenarios":"Calling registerCodeHighlighting(editor, ShikiTokenizer) or mounting the Shiki CodeHighlightPlugin on an editor created without CodeNode and CodeHighlightNode in its nodes list.","commonSituations":"Setting up the Shiki highlighter in an editor that previously used plain text only; migrating from @lexical/code to @lexical/code-shiki and dropping the node registration; building a minimal editor with a custom nodes array that omitted code nodes.","solutions":["Add CodeNode and CodeHighlightNode to the editor's nodes array at creation","Register the code extension via buildEditorFromExtensions so nodes are included","Guard the call with editor.hasNodes([CodeNode, CodeHighlightNode]) and register the nodes first"],"exampleFix":"// before\nconst editor = createEditor({nodes: [ParagraphNode, TextNode]});\nregisterCodeHighlighting(editor, ShikiTokenizer); // throws\n\n// after\nimport {CodeNode, CodeHighlightNode} from '@lexical/code';\nconst editor = createEditor({nodes: [ParagraphNode, TextNode, CodeNode, CodeHighlightNode]});\nregisterCodeHighlighting(editor, ShikiTokenizer); // ok","handlingStrategy":"validation","validationCode":"import {CodeNode, CodeHighlightNode} from '@lexical/code';\nif (!editor.hasNodes([CodeNode, CodeHighlightNode])) {\n  throw new Error('Register CodeNode and CodeHighlightNode before Shiki highlighting');\n}\nregisterCodeHighlighting(editor, ShikiTokenizer);","typeGuard":"function canUseShikiHighlighting(editor: LexicalEditor): boolean {\n  return editor.hasNodes([CodeNode, CodeHighlightNode]);\n}","tryCatchPattern":"try {\n  const unregister = registerCodeHighlighting(editor, ShikiTokenizer);\n} catch (e) {\n  if (String(e).includes('not registered on editor')) {\n    console.error('Shiki highlighting requires CodeNode and CodeHighlightNode', e);\n  }\n}","preventionTips":["Keep the @lexical/code node imports even when swapping tokenizer packages","Verify nodes with editor.hasNodes in your editor factory function","Register the shiki code extension instead of calling registerCodeHighlighting manually"],"tags":["lexical","node-registration","configuration","shiki"],"backgroundTag":"missing-node-registration","analyzedSha":"76a22dcba981b46119fcec45f935270707e26a57","analyzedAt":"2026-08-31T21:45:54.792Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}