A quick tour about how to change the NodeJS version of your Astro project

· astro  · 2 min read

How to change Astro NodeJS version

A quick tour about how to change the NodeJS version of your Astro project

Today I changed NodeJS in my Astro project. Changing a major version of the NodeJS platform can be dauting, let’s see the results.

Initial node version : 20

Targeted : 22

Steps to upgrade NodeJS in a Astro project

  • Step 1 : ensure that nodeJS 22 is installed at the root of my (local) project
nodejs --version
#v22.11.0
  • Step 2 : ensure version won’t randomly change

I use asdf, but you can use any version manager you prefer. I highly recommend to fix the version once for all. For asdf, it’s by adding a .tool-versions at the root of the project

#inside .tool-versions
nodejs 22.11.0
  • Step 3 : remove node_modules. I’m not even sure it is necessary, but I feel reassured to do so.

  • Step 4 : run npm i

  • Step 5 : run npm audit fix. This was proposion by the Terminal, so I ran it, 2 sub-dependencies changed.

  • Step 6 : Make your production server aware of the change. On my side, I used render.com on this project, and the node version is ensured by a NODE_VERSION variable. It depends on your server.

  • Step 7 : Push the changes to production

This is pretty straightforward, I’m not sure it’s always so easy for other NodeJS project, at least that was my honest attempt with Astro.

To my surprise, no big changes, no bug, and almost nothing to commit (only the package-lock.json)

Maybe because it’s only used as static website generator.

Summary

Very easy and without bug - which is to be noticed for a NodeJS project ;)

Enjoy!j

Back to Blog

Related Posts

View All Posts »