greensock/GSAP · warning
scrollTo target doesn't exist. Using 0
Error message
scrollTo target doesn't exist. Using 0
What it means
ScrollToPlugin's _getOffset resolves the scroll target to an element to measure its position. If the passed target (selector or element) resolves to nothing without getBoundingClientRect, it warns "scrollTo target doesn't exist. Using 0" and scrolls to offset 0 instead of the intended position.
Source
Thrown at src/ScrollToPlugin.js:50
},
_clean = (value, index, target, targets) => {
_isFunction(value) && (value = value(index, target, targets));
if (typeof(value) !== "object") {
return _isString(value) && value !== "max" && value.charAt(1) !== "=" ? {x: value, y: value} : {y: value}; //if we don't receive an object as the parameter, assume the user intends "y".
} else if (value.nodeType) {
return {y: value, x: value};
} else {
let result = {}, p;
for (p in value) {
result[p] = p !== "onAutoKill" && _isFunction(value[p]) ? value[p](index, target, targets) : value[p];
}
return result;
}
},
_getOffset = (element, container) => {
element = _toArray(element)[0];
if (!element || !element.getBoundingClientRect) {
return console.warn("scrollTo target doesn't exist. Using 0") || {x:0, y:0};
}
let rect = element.getBoundingClientRect(),
isRoot = (!container || container === _window || container === _body),
cRect = isRoot ? {top:_docEl.clientTop - (_window.pageYOffset || _docEl.scrollTop || _body.scrollTop || 0), left:_docEl.clientLeft - (_window.pageXOffset || _docEl.scrollLeft || _body.scrollLeft || 0)} : container.getBoundingClientRect(),
offsets = {x: rect.left - cRect.left, y: rect.top - cRect.top};
if (!isRoot && container) { //only add the current scroll position if it's not the window/body.
offsets.x += _buildGetter(container, "x")();
offsets.y += _buildGetter(container, "y")();
}
return offsets;
},
_parseVal = (value, target, axis, currentVal, offset) => !isNaN(value) && typeof(value) !== "object" ? parseFloat(value) - offset : (_isString(value) && value.charAt(1) === "=") ? parseFloat(value.substr(2)) * (value.charAt(0) === "-" ? -1 : 1) + currentVal - offset : (value === "max") ? _max(target, axis) - offset : Math.min(_max(target, axis), _getOffset(value, target)[axis] - offset),
_initCore = () => {
gsap = _getGSAP();
if (_windowExists() && gsap && typeof(document) !== "undefined" && document.body) {
_window = window;
_body = document.body;
_docEl = document.documentElement;View on GitHub (pinned to 13e2b79054)
Solutions
- Verify the target element exists before creating the scrollTo tween
- Correct the selector string or pass an Element reference
- Re-create the tween after the target element renders (e.g., in useEffect/onMount)
- Guard with document.querySelector check before animating
Example fix
// before
gsap.to(window, { scrollTo: '#section-3' });
// after
const target = document.querySelector('#section-3');
if (target) gsap.to(window, { scrollTo: target });
else console.warn('scroll target missing'); Defensive patterns
Strategy: validation
Validate before calling
function resolveScrollTarget(t) {
const el = typeof t === 'string' ? document.querySelector(t) : t;
if (!(el instanceof Element)) throw new Error(`scrollTo target missing: ${t}`);
return el;
}
gsap.to(window, { scrollTo: resolveScrollTarget('#section-3') }); Type guard
function isElement(v) { return v instanceof Element; } Try / catch
try {
gsap.to(window, { scrollTo: sel });
} catch (e) {
console.warn('scrollTo skipped:', e.message);
} Prevention
- Resolve and assert the target element before building the tween
- Re-create tweens when SPA content re-renders
- Avoid hard-coded selector strings scattered across modules
When it happens
Trigger: gsap.to(window, {scrollTo: "#missing"}) or scrollTo: {y: "#el"} where the selector matches nothing, the element was unmounted, or a null/undefined target value was passed into scrollTo.
Common situations: Anchor id typos, elements removed by SPA navigation before the tween runs, tween created before dynamic content rendered, or conditional rendering removing the target section.
Related errors
- Element not found: ${t}
- ScrollSmoother needs a valid content element.
- Element not found:
- ${elOrNode} not found
- GSDevTools error: invalid animation.
AI-assisted analysis of greensock/GSAP@13e2b79054 (2026-08-29).
Data as JSON: /api/errors/0c577c81c2604388.
Report an issue: GitHub.