Tools unable to determine the proper worker count

It is impossible to determine the proper usable CPU count currently.
This leads to problems like here:

When building a react-native app this is very problematic as the process easily crashes without any error message because of an out of memory error.

The code responsible for getting the worker count in RN is here:
The same applies to gradle. It also has a worker count of 36.

My current workaround is the following:

const defaultConfig = require('./metro.config.js')
module.exports = {
  maxWorkers: process.env.TOTAL_CPUS || 1, /* CircleCI: The issue with this on Dockerized services such as CircleCI is
                                              that the container thinks it has access to all of the hosts cores,
                                              although its being limited down to 4 by another process.
  cacheStores: []


  TOTAL_CPUS: 3 # For class medium+