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:
- I used nvm to switch to Node.js version 16 by running
nvm use v16.20.1
andnvm alias default v16.20.1
. This successfully allowed me to run the project without errors. - I considered upgrading the React Native version for this project to be patible with Node.js version 18, but the process seemed to be plex 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 being 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!
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:
- I used nvm to switch to Node.js version 16 by running
nvm use v16.20.1
andnvm alias default v16.20.1
. This successfully allowed me to run the project without errors. - I considered upgrading the React Native version for this project to be patible with Node.js version 18, but the process seemed to be plex 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 being 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!
Share Improve this question asked Jul 19, 2023 at 5:07 ThorinThorin 1892 gold badges3 silver badges12 bronze badges 1-
To fix the
open-ssl
what i did was i created a.npmrc
then addednode-options="--openssl-legacy-provider"
to that. seems like this fixed the issue for now. – Thorin Commented Jul 19, 2023 at 5:30
4 Answers
Reset to default 6I 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.
In order to use a specific version of node in your react native project, you can set it inside of the project.ext.react config at the root level of your app/build.gradle file as follows:
project.ext.react = [
...
nodeExecutableAndArgs: ['/path/to/your/node'],
...
]
for example, using nvm in a mac, you could use something similar to:
project.ext.react = [
...
nodeExecutableAndArgs: ['/Users/your.user/.nvm/versions/node/v16.13.0/bin/node'],
...
]
Good news
The good news is that almost all editors allow you to set the node version as the default value and run exactly this version of NodeJS for the same project, without third-party software.
First option
Using the WebStorm IDE as an example: Settings -> Languages & Frameworks -> Node.js -> this set node version -> apply and ok.
Second option
scripts: {
"preinstall": "nvm install 0.12.1",
"prestart": "nvm use 0.12.1", // <= This will install the correct node version before starting
"start": "node ./file1.js"
},
The below options are likely irrelevant — I'm not an nvm
user so wasn't aware of the config, but you can set Node versions per project in a .npmrc file.
Other options:
Docker (or other container systems, or VMs) are a good solution for this, and a mon way to handle requirements for specific runtime versions in production.
Using the OpenSSL legacy provider is also an option, but I would not remend doing this long-term because it may not be supported in the future, and may lead to security issues.
Another option is to install Node itself as a local dependency. You can do that with the package node by installing at a specific version. This is a hacky workaround, but because of the folks who worked on it, it seems trustworthy.