Repository: electron/electron (language: cpp)

Issue:
[Bug]: Regression: #35930 broke CJS via ESM loading when exporting null/undefined with ELECTRON_RUN_AS_NODE
### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a bug report that matches the one I want to file, without success.

### Electron Version

22.0.3

### What operating system are you using?

Ubuntu

### Operating System Version

Ubuntu 22.10

### What arch are you using?

x64

### Last Known Working Electron version

20.3.1 / 21.1.0

### Expected Behavior

1. `npm i electron@20.3.1 ava`
2. `ELECTRON_RUN_AS_NODE=true ./node_modules/.bin/electron ./node_modules/.bin/ava`
3. Works (can't find any tests obviously)

I was successfully running my esm tests via `ELECTRON_RUN_AS_NODE` until now

### Actual Behavior

1. `npm i electron@20.3.2 ava`
2. `ELECTRON_RUN_AS_NODE=true ./node_modules/.bin/electron ./node_modules/.bin/ava`
3. Crashes

```
node:internal/modules/esm/translators:178
      if (!ObjectPrototypeHasOwnProperty(exports, exportName) ||
           ^

TypeError: Cannot convert undefined or null to object
    at hasOwnProperty (<anonymous>)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:178:12)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)
```

### Testcase Gist URL

_No response_

### Additional Information

I was able to track this down and repro without ava as well (https://github.com/avajs/ava/discussions/3155). It appears you can no longer export `null` because it crashes the esm loader patch.

index.mjs

```js
import m from './module.cjs';
```

module.cjs

```js
module.exports = null;
```

`ELECTRON_RUN_AS_NODE=true ./node_modules/.bin/electron index.mjs`

It broke between `20.3.1` and `20.3.2` because of #35930 . If you're curious, in ava this comes from this dep https://github.com/jamiebuilds/ci-parallel-vars/blob/994940e4882bdddf046a5c076b49d700449e4b38/index.js#L41-L56

> Weirdly, this is like the 4th time I've tried this. 

@MarshallOfSound fifth time is the charm


Discussion / hints:
I think this is the culprit, because it assumes you can only export objects when in reality you can export anything.

```js
Object.keys(module.exports)
```

Fix patch:
diff --git a/patches/node/fix_expose_the_built-in_electron_module_via_the_esm_loader.patch b/patches/node/fix_expose_the_built-in_electron_module_via_the_esm_loader.patch
index 4d18cbb616238..5fb1654831390 100644
--- a/patches/node/fix_expose_the_built-in_electron_module_via_the_esm_loader.patch
+++ b/patches/node/fix_expose_the_built-in_electron_module_via_the_esm_loader.patch
@@ -51,7 +51,7 @@ index 7cec4e9a3e3675ba75d66a44ed4e142d13ca1821..0c7aad193442a7e5cab62638441969a7
    }
  }
 diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
-index 6f25b2e67ab77613c6ed63c227bb875d5461f45f..d1527b859bbea15fdf30622fc8f2700bde5b4591 100644
+index 6f25b2e67ab77613c6ed63c227bb875d5461f45f..010fa8f78a21a8146879849e2e887332e2694e51 100644
 --- a/lib/internal/modules/esm/translators.js
 +++ b/lib/internal/modules/esm/translators.js
 @@ -154,7 +154,7 @@ translators.set('commonjs', async function commonjsStrategy(url, source,
@@ -63,15 +63,19 @@ index 6f25b2e67ab77613c6ed63c227bb875d5461f45f..d1527b859bbea15fdf30622fc8f2700b
      [...exportNames] : ['default', ...exportNames];
  
    return new ModuleWrap(url, undefined, namesWithDefault, function() {
-@@ -173,7 +173,7 @@ translators.set('commonjs', async function commonjsStrategy(url, source,
+@@ -173,9 +173,9 @@ translators.set('commonjs', async function commonjsStrategy(url, source,
        }
      }
  
 -    for (const exportName of exportNames) {
+-      if (!ObjectPrototypeHasOwnProperty(exports, exportName) ||
+-          exportName === 'default')
 +    for (const exportName of namesWithDefault) {
-       if (!ObjectPrototypeHasOwnProperty(exports, exportName) ||
-           exportName === 'default')
++      if (exportName === 'default' ||
++          !ObjectPrototypeHasOwnProperty(exports, exportName))
          continue;
+       // We might trigger a getter -> dont fail.
+       let value;
 diff --git a/lib/internal/url.js b/lib/internal/url.js
 index 40b25f6890b5db721923ba2e9cc351e514ca22bc..288f3253b4c686d1b061dfcdf18dc95794943d87 100644
 --- a/lib/internal/url.js


Test patch: