Cannot find relative main module using remote in renderer
See original GitHub issueDescribe the issue / bug.
As per the Electron documentation of the remote module: “Modules specified by their relative path will resolve relative to the entrypoint of the main process.” But when trying const foo = require('electron').remote.require('./foo'); in the renderer process it throws Error: Cannot find module ‘./foo’. This might be related to the webpack config as discussed in #42.
How can I reproduce this problem?
project/
├── main
│ ├── foo.js
│ └── index.js
└── renderer
└── main.js
// some relative module: main/foo.js
module.exports = 'bar';
// renderer process: renderer/main.js
import Vue from 'vue';
const foo = require('electron').remote.require('./foo');
Tell me about your development environment.
- Node version: 8.1.2
- NPM version: 5.0.3
- vue-cli version: 2.8.2
- Operating System: macOS Sierra
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
electron Cant find module remote in the renderer process
Try with this code const app = require('electron').remote.app. And in your Main process you can do this : const {app, ipcMain, BrowserWindow ...
Read more >Electron's 'remote' module considered harmful | by Jeremy Rose
Electron, being based on Chromium, inherits Chromium's multi-process model. There are one or several renderer processes, which are responsible ...
Read more >remote | Electron
Use main process modules from the renderer process. Process: Renderer. The remote module provides a simple way to do inter-process communication (IPC) between ......
Read more >Basics of rendering and exporting in After Effects CC
Note: The embedded version of the Adobe Media Encoder used to manage export settings within After Effects output modules does not provide all ......
Read more >rollup.js
A config file is an ES module that exports a default object with the desired options: export default { input: 'src/main.js', output: {...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi @SimulatedGREG!
I was on holidays but just came back and found what I believe to be a good solution by editing the
webpack.main.config.jsand manually adding every relative module as new entries.This is expected behavior with the presence of
webpack, as it will bundle allmainprocess code (within the dependency tree) into one single file. So theremote.requiremethods will not work with the initial setup asfoo.jswill never make it to production.It might be worth updating the
webpackconfiguration to support this in the future, but for the time being this will be on the back burner.Related: https://simulatedgreg.gitbooks.io/electron-vue/content/en/file-tree.html