skip to Main Content

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!

2

Answers


  1. 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"
    },
    
    Login or Signup to reply.
  2. 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 common way to handle requirements for specific runtime versions in production.

    Using the OpenSSL legacy provider is also an option, but I would not recommend 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search