How to avoid remote.require


If I require('mymodule') directly in the renderer, I get the error:

Error: Cannot find module 'mymodule'
    at Module._resolveFilename (module.js:470)
    at Function.Module._resolveFilename (VM65:35)
    at Function.Module._load (module.js:418)
    at Module.require (module.js:498)
    at require (internal/module.js:20)

As a workaround, I am currently using require('electron').remote.require('mymodule'). Unfortunately because I need to pass a large amount of data to my module’s function, the performance implications of the remote-require-proxy are prohibitive.

Am I able to use an explicit path in my require() to avoid the error above when requiring directly?


Maybe try app-module-path


Thanks for the suggestion! I didn’t end up using this but you got me trying a few things and I realized that if I got the absolute path using require.resolve in the main process, I could use that absolute path in the renderer as well. I had tried it previously but obviously had done something wrong. Works just fine.


Looks like it got fixed in newer version.