{"record":{"id":"83fd1ea17d701c39","repo":"greensock/GSAP","slug":"a-motion-path-must-have-at-least-two-anchors","errorCode":null,"errorMessage":"A motion path must have at least two anchors.","messagePattern":"A motion path must have at least two anchors\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/MotionPathHelper.js","lineNumber":196,"sourceCode":"\t\t\tvars.anchorSnap = p => {\n\t\t\t\tif (p.x * p.x + p.y * p.y < 16) {\n\t\t\t\t\tp.x = p.y = 0;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tanimationToScrub = animation && animation.parent && animation.parent.data === \"nested\" ? animation.parent.parent : animation;\n\n\t\tvars.onPress = () => {\n\t\t\tanimationToScrub.pause(0);\n\t\t};\n\n\t\trefreshPath = () => {\n\t\t\t//let m = _getConsolidatedMatrix(path);\n\t\t\t//animation.vars.motionPath.offsetX = m.e - offset.x;\n\t\t\t//animation.vars.motionPath.offsetY = m.f - offset.y;\n\t\t\tif (this.editor._anchors.length < 2) {\n\t\t\t\tconsole.warn(\"A motion path must have at least two anchors.\");\n\t\t\t} else {\n\t\t\t\tanimation.invalidate();\n\t\t\t\tanimationToScrub.restart();\n\t\t\t}\n\t\t};\n\t\tvars.onRelease = vars.onDeleteAnchor = refreshPath;\n\n\t\tthis.editor = PathEditor.create(path, vars);\n\t\tif (vars.center) {\n\t\t\tgsap.set(target, {transformOrigin:\"50% 50%\", xPercent:-50, yPercent:-50});\n\t\t}\n\t\tif (animation) {\n\t\t\tif (animation.vars.motionPath.path) {\n\t\t\t\tanimation.vars.motionPath.path = path;\n\t\t\t} else {\n\t\t\t\tanimation.vars.motionPath = {path:path};\n\t\t\t}\n\t\t\tif (animationToScrub.parent !== gsap.globalTimeline) {","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/greensock/GSAP/blob/13e2b790546426a1a2e0e9b409f3f8dc6d6611f2/src/MotionPathHelper.js#L178-L214","documentation":"MotionPathHelper's editor requires at least two anchor points to represent a path. When the path editor's anchor list drops below two (e.g. after deleting anchors or supplying a degenerate path), refreshPath warns instead of invalidating/restarting the scrub animation.","triggerScenarios":"Deleting anchors in the visual editor until one remains; passing a path element/motionPath with a single point; path data that consolidates to fewer than two anchors on release.","commonSituations":"Manual editing sessions where users remove points; programmatically generated paths with insufficient points; SVG path with only a moveto command.","solutions":["Ensure the motion path has at least two anchor points","Guard anchor deletion so at least two remain","Regenerate the path from valid multi-point data before attaching the helper"],"exampleFix":"// before\nvars.onDeleteAnchor = () => { editor.deleteSelectedAnchor(); }; // can drop to 1\n// after (library-internal guard)\nif (editor._anchors.length < 2) {\n  console.warn(\"A motion path must have at least two anchors.\");\n  return;\n}","handlingStrategy":"validation","validationCode":"const pts = pathData.trim().split(/(?=[ML])/); if (pts.length < 2) { throw new Error('Path needs at least 2 anchors'); }","typeGuard":"const hasEnoughAnchors = (editor) => Array.isArray(editor?._anchors) && editor._anchors.length >= 2;","tryCatchPattern":null,"preventionTips":["Validate path data (>=2 points) before creating MotionPathHelper","Disable anchor deletion below two anchors in custom editor UIs","Sanitize dynamically generated SVG paths for degenerate single-point data"],"tags":["gsap","motionpath","invalid-input"],"backgroundTag":"path-needs-two-anchors","analyzedSha":"13e2b790546426a1a2e0e9b409f3f8dc6d6611f2","analyzedAt":"2026-08-29T08:34:05.027Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}