{"record":{"id":"0390c4a6245eebb1","repo":"juliangarnier/anime","slug":"can-t-morph-to-an-invalid-target-path2-must-res","errorCode":null,"errorMessage":"Can't morph to an invalid target. 'path2' must resolve to an existing <path>, <polygon> or <polyline> SVG element.","messagePattern":"Can't morph to an invalid target\\. 'path2' must resolve to an existing <path>, <polygon> or <polyline> SVG element\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/svg/morphto.js","lineNumber":28,"sourceCode":" * @import {\n *   TargetsParam,\n *   FunctionValue\n * } from '../types/index.js'\n*/\n\n/**\n * @param  {TargetsParam} path2\n * @param  {Number} [precision]\n * @return {FunctionValue}\n */\nexport const morphTo = (path2, precision = .33) => ($path1, index, total, prevTween) => {\n  const tagName1 = ($path1.tagName || '').toLowerCase();\n  if (!tagName1.match(/^(path|polygon|polyline)$/)) {\n    throw new Error(`Can't morph a <${$path1.tagName}> SVG element. Use <path>, <polygon> or <polyline>.`);\n  }\n  const $path2 = /** @type {SVGGeometryElement} */(getPath(path2));\n  if (!$path2) {\n    throw new Error(\"Can't morph to an invalid target. 'path2' must resolve to an existing <path>, <polygon> or <polyline> SVG element.\");\n  }\n  const tagName2 = ($path2.tagName || '').toLowerCase();\n  if (!tagName2.match(/^(path|polygon|polyline)$/)) {\n    throw new Error(`Can't morph a <${$path2.tagName}> SVG element. Use <path>, <polygon> or <polyline>.`);\n  }\n  const isPath = $path1.tagName === 'path';\n  const separator = isPath ? ' ' : ',';\n  const previousPoints = prevTween ? prevTween._value : null;\n  if (previousPoints) $path1.setAttribute(isPath ? 'd' : 'points', previousPoints);\n\n  let v1 = '', v2 = '';\n\n  if (!precision) {\n    v1 = $path1.getAttribute(isPath ? 'd' : 'points');\n    v2 = $path2.getAttribute(isPath ? 'd' : 'points');\n  } else {\n    const length1 = /** @type {SVGGeometryElement} */($path1).getTotalLength();\n    const length2 = $path2.getTotalLength();","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/juliangarnier/anime/blob/01b81be1df6843ccfe0a71c0699a746bf740dd77/src/svg/morphto.js#L10-L46","documentation":"Error \"Can't morph to an invalid target. 'path2' must resolve to an existing <path>, <polygon> or <polyline> SVG element.\" thrown in juliangarnier/anime.","triggerScenarios":"Thrown at src/svg/morphto.js:28 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a valid selector, element or path string that resolves to an existing <path>, <polygon> or <polyline> in the DOM.","Verify the target element exists and is mounted before the morph animation starts."],"exampleFix":"// Wrong: '#missing' matches nothing\nsvg.morphTo('#missing');\n// Fix: target an existing morphable element\n// <path id=\"target\" d=\"M10 10 H90 V90 H10 Z\"/>\nsvg.morphTo('#target');","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01b81be1df6843ccfe0a71c0699a746bf740dd77","analyzedAt":"2026-08-12T23:45:07.335Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}