question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find relative main module using remote in renderer

See original GitHub issue
Describe 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:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
Puigcerbercommented, Jul 19, 2017

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.js and manually adding every relative module as new entries.

let mainConfig = {
  entry: {
    main: path.join(__dirname, '../src/main/index.js'),
    foo: path.join(__dirname, '../src/main/foo.js')
  },
}
1reaction
SimulatedGREGcommented, Jul 1, 2017

This is expected behavior with the presence of webpack, as it will bundle all main process code (within the dependency tree) into one single file. So the remote.require methods will not work with the initial setup as foo.js will never make it to production.

It might be worth updating the webpack configuration 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found