{"record":{"id":"5fa5d2702edc0330","repo":"pbakaus/impeccable","slug":"config-insertbefore-or-config-insertafter-string","errorCode":null,"errorMessage":"config.insertBefore or config.insertAfter (string) required","messagePattern":"config\\.insertBefore or config\\.insertAfter \\(string\\) required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugin/skills/impeccable/scripts/live-inject.mjs","lineNumber":466,"sourceCode":"\nfunction validateConfig(cfg) {\n  if (!cfg || typeof cfg !== 'object') throw new Error('config.json must be an object');\n  if (!Array.isArray(cfg.files) || cfg.files.length === 0) {\n    throw new Error('config.files (non-empty string array) required');\n  }\n  if (!cfg.files.every((f) => typeof f === 'string' && f.length > 0)) {\n    throw new Error('config.files must contain only non-empty strings');\n  }\n  if (cfg.exclude !== undefined) {\n    if (!Array.isArray(cfg.exclude)) {\n      throw new Error('config.exclude, if present, must be a string array');\n    }\n    if (!cfg.exclude.every((f) => typeof f === 'string' && f.length > 0)) {\n      throw new Error('config.exclude must contain only non-empty strings');\n    }\n  }\n  if (typeof cfg.insertBefore !== 'string' && typeof cfg.insertAfter !== 'string') {\n    throw new Error('config.insertBefore or config.insertAfter (string) required');\n  }\n  if (cfg.commentSyntax !== 'html' && cfg.commentSyntax !== 'jsx') {\n    throw new Error(\"config.commentSyntax must be 'html' or 'jsx'\");\n  }\n  if (cfg.cspChecked !== undefined && typeof cfg.cspChecked !== 'boolean') {\n    throw new Error(\"config.cspChecked, if present, must be a boolean\");\n  }\n}\n\n// ---------------------------------------------------------------------------\n// Auto-execute\n// ---------------------------------------------------------------------------\n\nconst _running = process.argv[1];\nif (_running?.endsWith('live-inject.mjs') || _running?.endsWith('live-inject.mjs/')) {\n  enterLiveRoot();\n  injectCli();\n}","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/pbakaus/impeccable/blob/d14711ae3d1a1dd62dee61a358d27f107c51ccd0/plugin/skills/impeccable/scripts/live-inject.mjs#L448-L484","documentation":"Sixth validateConfig() check: at least one of cfg.insertBefore or cfg.insertAfter must be a string. These are the anchor selectors used by insertTag() to place the live <script>; without one the injector has no insertion point. Both may be strings (insertBefore wins), but neither being a string is fatal.","triggerScenarios":"Both keys absent; both null; one present but as a non-string (e.g. a regex or array); only commentSyntax and files provided. The injector needs a literal string like '</head>' or '<body>' to locate the tag insertion point.","commonSituations":"Setup wizard didn't detect an anchor and left both blank; user removed the anchor keys thinking the injector would default; config copied from a project whose anchors differed; value accidentally set to a number or object.","solutions":["Set insertBefore to a string marker that exists in your HTML (e.g. '</head>' or '</body>') or insertAfter to an opening tag (e.g. '<body>').","Re-run live setup so the wizard detects the anchor from your entry-point file.","If using a framework adapter (Nuxt etc.) the adapter supplies its own insertion logic, but validateConfig still requires one of the two keys as a string.","Validate with `node live-inject.mjs --check`."],"exampleFix":"// before\n{ \"files\": [\"index.html\"], \"commentSyntax\": \"html\" }\n\n// after\n{ \"files\": [\"index.html\"], \"commentSyntax\": \"html\", \"insertBefore\": \"</head>\" }","handlingStrategy":"validation","validationCode":"function hasInsertAnchor(cfg) {\n  return typeof cfg?.insertBefore === 'string' || typeof cfg?.insertAfter === 'string';\n}\nif (!hasInsertAnchor(cfg)) {\n  throw new Error('Provide config.insertBefore or config.insertAfter as a string anchor.');\n}","typeGuard":"/** True when at least one anchor is a string. */\nfunction hasAnchor(cfg) {\n  return typeof cfg?.insertBefore === 'string' || typeof cfg?.insertAfter === 'string';\n}","tryCatchPattern":"try {\n  validateConfig(cfg);\n} catch (err) {\n  if (/insertBefore or config\\.insertAfter/.test(err.message)) {\n    cfg.insertBefore = '</head>';\n    validateConfig(cfg);\n  }\n  throw err;\n}","preventionTips":["Always set insertBefore (e.g. '</head>') or insertAfter (e.g. '<body>') as a string anchor.","Re-run live setup so the wizard detects an anchor from your entry-point file.","Even with a framework adapter, keep one anchor string to satisfy validation."],"tags":["live-inject","config","validation","json"],"backgroundTag":null,"analyzedSha":"d14711ae3d1a1dd62dee61a358d27f107c51ccd0","analyzedAt":"2026-08-13T00:52:25.771Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}