'Next.js error "Unhandled Runtime Error TypeError: Cannot read properties of undefined (reading 'scrollTo')"
While making a portfolio website with Next.js, this is some sort of scrolling error that I'm getting from .next
folder in my project folder.
Whenever I'm trying to get the mobile responsive view of the website this is the error I'm facing
Unhandled Runtime Error
TypeError: Cannot read properties of undefined (reading 'scrollTo')
This is the location of the error file
.next\static\chunks\pages\index.js (14:16) @ scroll
This is the code in that location
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i];
}
return arr2;
}
This is the snapshot of the error
I can run the website locally even when the error is showing. Is it gonna be a buggy thing if I deploy it?
How do I fix this?
Solution 1:[1]
You've got this error on Runtime
and it is on browser
Since node
is not available on the browser (only on node), you will need to use window.scrollTo
instead
To completely remove it from the error logs, do a rebuilt so your .next
will be wipe out and take the latest changes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ryan Le |