{"record":{"id":"1fcead6d57781e3a","repo":"facebook/lexical","slug":"codehighlightplugin-codenode-or-codehighlightnode","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-prism/src/CodeHighlighterPrism.ts","lineNumber":436,"sourceCode":"      $textNodeTransform.bind(null, editor, tokenizer, transformState),\n    ),\n  );\n\n  return mergeRegister(...registrations);\n}\n\n/**\n * Register the Prism 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 CodePrismExtension}.\n */\nexport function registerCodeHighlighting(\n  editor: LexicalEditor,\n  tokenizer: Tokenizer = PrismTokenizer,\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 CodePrismConfig {\n  /**\n   * When true, the Prism 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":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/facebook/lexical/blob/76a22dcba981b46119fcec45f935270707e26a57/packages/lexical-code-prism/src/CodeHighlighterPrism.ts#L418-L454","documentation":"registerCodeHighlighting() in @lexical/code-prism refuses to run unless the editor knows about both CodeNode and CodeHighlightNode, because the highlighting transforms and decorations can only operate on those node classes. Lexical editors only handle node types explicitly registered at creation, so attempting to highlight code without them means the plugin could encounter nodes it cannot process. The library throws eagerly at registration time instead of failing later during an update.","triggerScenarios":"Calling registerCodeHighlighting(editor) (or mounting CodeHighlightPlugin, which calls it) on an editor whose initial nodes config omitted CodeNode or CodeHighlightNode.","commonSituations":"Adding a code block to a rich-text editor that was created with createEditor({nodes: [...]}) or buildEditorFromExtensions without including the code nodes; copying plugin setup from docs into an editor configured with a hand-picked nodes list; switching from the umbrella @lexical/code package to the @lexical/code-prism package and forgetting the nodes are no longer auto-registered.","solutions":["Add CodeNode and CodeHighlightNode (from @lexical/code or @lexical/code-prism) to the editor's nodes array","If using extensions, include the code extension (e.g. CodeHighlightExtension) in buildEditorFromExtensions so nodes are registered automatically","Verify with editor.hasNodes([CodeNode, CodeHighlightNode]) before calling registerCodeHighlighting"],"exampleFix":"// before\nconst editor = createEditor({nodes: [HeadingNode, QuoteNode]});\nregisterCodeHighlighting(editor); // throws\n\n// after\nimport {CodeNode, CodeHighlightNode} from '@lexical/code';\nconst editor = createEditor({nodes: [HeadingNode, QuoteNode, CodeNode, CodeHighlightNode]});\nregisterCodeHighlighting(editor); // ok","handlingStrategy":"validation","validationCode":"import {CodeNode, CodeHighlightNode} from '@lexical/code';\nif (!editor.hasNodes([CodeNode, CodeHighlightNode])) {\n  throw new Error('Register CodeNode and CodeHighlightNode before enabling code highlighting');\n}\nregisterCodeHighlighting(editor);","typeGuard":"function canHighlight(editor: LexicalEditor): boolean {\n  return editor.hasNodes([CodeNode, CodeHighlightNode]);\n}","tryCatchPattern":"try {\n  const unregister = registerCodeHighlighting(editor);\n} catch (e) {\n  if (String(e).includes('not registered on editor')) {\n    console.error('Add CodeNode and CodeHighlightNode to your editor config', e);\n  }\n}","preventionTips":["Always list every feature node class in the editor's nodes array at creation","Prefer extension bundles (buildEditorFromExtensions) that register nodes for you","Assert node registration once at editor setup with editor.hasNodes in dev builds"],"tags":["lexical","node-registration","configuration"],"backgroundTag":"missing-node-registration","analyzedSha":"76a22dcba981b46119fcec45f935270707e26a57","analyzedAt":"2026-08-31T21:45:54.792Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}