Upgrading Node and npm versions when upgrading an existing Gatby 3 production site to Gatsby 4.2

ref: 8b921b8a-0aba-4b0c-889a-c056ae17a61a
site: codestaffio-new

I will be upgrading an existing Gatby 3 production site to Gatsby 4.2.
I’ve used Node v16.6.2 npm 8.0.0 on my localhost for development work in a separate “development” branch.
When I deployed the development branch I realized the site currently uses node v10.24.1 (npm v6.14.12) as reported in the deployment log.
I’d prefer not to have to create a new project for this and have to re-implement the domain setup.
How can I approach this?

Hi @witcradg

You can use NODE_VERSION environment variable either set via the Netlify UI, or in a netlify.toml in the root of the repository to specify which node version you wish to use (also see Netlify Configuration Variables.)

I had completely forgotten about the toml file I set up a couple years ago. Thank you.
For anyone looking for a solution, I was able to resolve the issue by adding the following to the toml:

[context.development]
environment = { NODE_VERSION = “16.6.2” }

1 Like

Thanks so much for coming back and sharing your solution! We appreciate it!

This solution did NOT work when I tried it on a development branch for another website.
Again I’m trying to upgrade from Gatsby 3 to Gatsby 4.

Site name: musing-archimedes-d1870b
API ID: 980ca0e5-c770-4888-a904-2edaee0ec22e

When I try to do the new build I see that it’s still using the older Node version:
9:06:08 AM: Now using node v12.18.0 (npm v6.14.4)

My toml file looks like this:

[build]
  command = "npm run prod"
  publish = "public"

[context.development]
  environment = { NODE_VERSION = "16.6.2" }

This is a branch deploy so I believe that should be sufficient, but just in case, I added this but it didn’t work either:

[context.production]
  environment = { NODE_VERSION = "16.6.2" }

OK. I think I figured this out. The context has to be the branch name. For example, if your branch is “mybranch” your environment setting would look like this:

[context.mybranch]
  environment = { NODE_VERSION = "16.6.2" }

When I tried this, the build used the new Node v16.6.2.

2 Likes