te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Setting up specific Node.js version for a React Native project - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Setting up specific Node.js version for a React Native project - Stack Overflow

programmeradmin2浏览0评论

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 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:

  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 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 added node-options="--openssl-legacy-provider" to that. seems like this fixed the issue for now. – Thorin Commented Jul 19, 2023 at 5:30
Add a ment  | 

4 Answers 4

Reset to default 6

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.

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.

发布评论

评论列表(0)

  1. 暂无评论