Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up specific Node.js version for a React Native project

I am facing an issue while trying to run an old React Native project (version 0.67) on my Mac. The problem seems to be related to OpenSSL, and it occurs when using Node.js version 18, which is the default on my system. However, when I switch to Node.js version 16 using nvm, the project runs without any issues.

Here's what I have tried so far:

  1. I used nvm to switch to Node.js version 16 by running nvm use v16.20.1 and nvm alias default v16.20.1. This successfully allowed me to run the project without errors.
  2. I considered upgrading the React Native version for this project to be compatible with Node.js version 18, but the process seemed to be complex and time-consuming.

Now, I have multiple projects on my machine, some of which require Node.js 18. Switching back and forth between Node.js versions using nvm is becoming cumbersome. Is there a way to configure this specific React Native project to use Node.js version 16 when running it, while keeping my other projects on Node.js version 18?

Any guidance on how to set up a specific Node.js version for a React Native project would be greatly appreciated. Thank you!

like image 916
Thorin Avatar asked Sep 11 '25 03:09

Thorin


1 Answers

I use NVM to manage node versions for a number of react-native projects. I have found that when starting a project from the terminal, metro will start using whatever the alias'd default node version is, and not the version specified by nvm use.

So, prior to starting up a particular project i will ensure that i run both (for example):

nvm alias default v18.18.0
nvm use v18.18.0

If i need to swap back to some other version, i will do the same thing:

nvm alias default v16.16.0
nvm use v16.16.0

I use nvm list to verify my settings are correct.

like image 161
Dylan Hillier Avatar answered Sep 12 '25 17:09

Dylan Hillier