Skip to content

Commit 46af3ce

Browse files
authored
Clarify remote require of relative modules
The docs for the `remote.require(module)` method were a little too terse for me to understand the behavior of relative module loading for `remote.require` and I had to run an experiment to understand the behavior (e.g. is the relative path relative to caller of `remote.require` or relative to some other path in the project related to the main process?). I think this is correct but someone please double check my understanding. Adding an example and additional explanation should help clarify this. Feel free to edit the copy as needed.
1 parent 48152a8 commit 46af3ce

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

docs/api/remote.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,26 @@ The `remote` module has the following methods:
140140

141141
* `module` String
142142

143-
Returns `any` - The object returned by `require(module)` in the main process.
143+
Returns `any` - The object returned by `require(module)` in the main process. Modules specified by their relative path will resolve relative to the entrypoint of the main process.
144+
145+
e.g.
146+
147+
```js
148+
// main process: main/index.js
149+
const { app, ipcMain } = require('electron')
150+
app.on('ready', () => {
151+
//...
152+
```
153+
154+
```js
155+
// some relative module: main/foo.js
156+
module.exports = 'bar'
157+
```
158+
159+
```js
160+
// renderer process: renderer/index.js
161+
const foo = require('electron').remote.require('./foo') // bar
162+
```
144163
145164
### `remote.getCurrentWindow()`
146165

0 commit comments

Comments
 (0)