Home
Support Forums

Using Node 14.x Doesn't Work

My site deployed successfully and I’m using Netlify Functions using JavaScript.

I have 1 specific function that errors with "errorType":"Runtime.UserCodeSyntaxError" that uses JavaScript’s new optional chaining (?), all the other ones are fine. Someone figured that their code was running on Node 14 while Netlify ran it in Node 12 in this thread, but instead of upgrading his Node version he just downgraded his code to support Node 12 syntax.

For me though, I want to do the opposite, I want to upgrade Netlify’s Node version to 14 instead of using 12.
Locally it doesn’t error and I’m using the versions:
Node: v14.17.0
Yarn: 1.22.10

On Netlify’s build image selection I am using Ubuntu Xenial 16.04 (default) which uses v12.x by default.

To select your own Node version you can do many things like .nvmrc, NODE_VERSION, etc., I choose both the options I mentioned above with the same version I am using v14.17.0. According to Netlify, they use the Amazon Lambdas which has support for Node 14.x.

My build was published successfully had this to say:

2:17:02 AM: Attempting node version 'v14.17.0' from .nvmrc
2:17:02 AM: Downloading and installing node v14.17.0...
2:17:02 AM: Downloading https://nodejs.org/dist/v14.17.0/node-v14.17.0-linux-x64.tar.xz...
2:17:03 AM: Computing checksum with sha256sum
2:17:03 AM: Checksums matched!
2:17:06 AM: Now using node v14.17.0 (npm v6.14.13)

So we are in fact forcing Netlify Node to use the same Node version I am using locally. The project also uses the correct version of Yarn. Now that everything is identical, environment wise, build-step wise, code-wise… I am still getting the Runtime.UserCodeSyntaxError on that 1 specific function that uses this code syntax:

const test = obj?.obj2?.obj3?.test

I know Node 14.x supports this new style and 12.x doesn’t but even my Netlify deploy logs tell me its using Node 14.x.

What is wrong here?

If you’re using optional chaining in Netlify Functions, the runtime is not the same as what you specify in Node build settings. You need to specify AWS Runtime like mentioned here: Build serverless functions with JavaScript | Netlify Docs

1 Like