0

I am getting this error with nodegit, and I am not sure if it is my fault for not knowing how to work with electron remote or it is a problem with nodegit. I did file an issue just in case.

In my main.js file for electron I can use nodegit without any issue.

On the web site I try to use nodegit with remote. I get an error. My code:

var remote = require('electron').remote;
var pathToRepo = remote.require('path').resolve(currentRepoDir);
remote.require('nodegit').Repository.open(pathToRepo).then(function(repo){
  console.log(repo);
}); 

I am getting the error:

Uncaught TypeError: require(...).remote.require(...).Repository.open is not a function

Why is open not a function?

Guildencrantz
  • 1,875
  • 1
  • 16
  • 30
Johnston
  • 20,196
  • 18
  • 72
  • 121
  • Why are you using `remote` though? The [remote module](http://electron.atom.io/docs/v0.36.0/api/remote/) essentially uses RMI which poses a number of shortcomings and generally should not be necessary. Is there a particular reason why you don't require 'path' and 'nodegit' directly, without remote? – inukshuk Jan 12 '16 at 11:52
  • @inukshuk I'll give that a try and update the question. What would be the use case for `remote`? – Johnston Jan 12 '16 at 11:54
  • In my opinion, the main use case for `remote` is when you need to access some of the Electron modules which are only available to the main process (e.g., remote.app) -- there is no way to require those directly in you renderer process. But node modules are available so there is really no reason I can think of to create them in the main process and access them via RMI unless you wanted to share state between the processes in some way. – inukshuk Jan 12 '16 at 11:58

1 Answers1

0

Why are you using remote.require?

remote.require('path')

Just use:

require('path')

require works in the render process too.

Tim
  • 7,746
  • 3
  • 49
  • 83