.at is not a function - nodejs

Hi guys, I’ve just deployed a working react and nodejs app to Render. Deployment went fine. When testing however, I found an error on the server “TypeError: messages.at is not a function” where messages is a non-empty array. It would appear that the at() function that was introduced in ECMAScript 2022 is not recognised. I thought this may be to do with Render defaulting to node 14.17.0 so added the required environment variable to bump it up to 18.12.1 (confirmed in the deployment logs) but I still get the same error. Any idea what I’ve missed?

Hi,

It seems the .at() method was introduced in Node 16.6.0. Which I tested and confirmed in my own projects, e.g.:

==> Detected Node version 16.5.0
==> Running build command 'node --version; node -e 'console.log([1,2,3].at(0))''...
v16.5.0
[eval]:1
console.log([1,2,3].at(0)) 
                    ^
TypeError: [1,2,3].at is not a function

versus

==> Detected Node version 16.6.0
==> Running build command 'node --version; node -e 'console.log([1,2,3].at(0))''...
v16.6.0
1

And the version you mentioned:

==> Detected Node version 18.12.1
==> Running build command 'node --version; node -e 'console.log([1,2,3].at(0))''...
v18.12.1
1

This would appear to be a code issue, which you may need to debug further.

Alan

Thanks for doing that Alan. As a work around I’ve replaced the 3 x .at() function calls with regular array indexing and it works fine. Strange given those were the only lines changed, so there’s obviously something else fishy going on. I’ll investigate further