Repository: electron/electron (language: cpp)

Issue:
[Bug]: `require('electron/lol')` inside an electron process requires the `'electron'` module instead
### 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

17.0.1

### What operating system are you using?

all

### Operating System Version

all

### What arch are you using?

all

### Last Known Working Electron version

9.4.4

### Expected Behavior

* Should throw a `MODULE_NOT_FOUND` error OR
* The difference between Electron's and Node.js' `require()` should be documented

### Actual Behavior

It requires the 'electron' module instead.

### Testcase Gist URL

https://gist.github.com/RaisinTen/dfe8c9ccc8345c656dcf0d21825c4b7f

### Additional Information

* This is a continuation of https://github.com/electron/electron/issues/32951 which was closed because requiring `electron/package.json` is not expected behaviour. This issue however, only focuses on the part where we decide whether we should allow users to require modules with names falling into this regex - `electron/.*` (not `package.json` in particular).
* This is likely happening due to the way https://github.com/electron/electron/blob/b1463d2da138dcbc20d87cf31b9807d697690592/lib/common/reset-search-paths.ts#L55-L61 is written. I'm suspecting this change - https://github.com/electron/electron/pull/22937, so cc @MarshallOfSound and @nornagon.


Discussion / hints:
This issue has been automatically marked as stale. **If this issue is still affecting you, please leave any comment** (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the [latest version of Electron](https://www.electronjs.org/releases/stable) or in the [beta](https://www.electronjs.org/releases/beta)—please include it with your comment!
Still relevant in all versions of Electron > 9.4.4.

Fix patch:
diff --git a/lib/common/reset-search-paths.ts b/lib/common/reset-search-paths.ts
index 82358923599a7..1bbaf03fcfb16 100644
--- a/lib/common/reset-search-paths.ts
+++ b/lib/common/reset-search-paths.ts
@@ -52,8 +52,9 @@ if (process.type === 'renderer') {
 }
 
 const originalResolveFilename = Module._resolveFilename;
+const electronModuleNames = new Set(['electron', 'electron/main', 'electron/renderer', 'electron/common']);
 Module._resolveFilename = function (request: string, parent: NodeModule, isMain: boolean, options?: { paths: Array<string>}) {
-  if (request === 'electron' || request.startsWith('electron/')) {
+  if (electronModuleNames.has(request)) {
     return 'electron';
   } else {
     return originalResolveFilename(request, parent, isMain, options);


Test patch: