0

I am working on a project using electron and nodegit, and I recently updated my dependencies. After solving the compatibility issues, I found two versions of nodegit and electron that work. But upon testing it, I found that async nodegit operations fail, while the synchronous ones work fine. Here's a code example that does not work:

const pathToRepo = require('path').resolve(path);
Git.Repository.open(pathToRepo)
.then((repo) => {
  console.log(repo);
})
.catch( (err) => {
  console.log(err);
});

Upon executing it, the promise returns an error which is caught by the catch block, and upon outputting the value on the console it simple displays true, and gives no additional information.

Also, I had updated node from 5 to 6.3 before updating my dependencies.

Previous:

electron-prebuilt: 0.37.8
nodegit: 0.13.0

After updating:

electron-prebuilt: 1.2.1
nodegit: 0.14.1

EDIT: Solved by adding an npm script:

"rebuild": "npm rebuild --runtime=electron --target=1.2.1 disturl=https://atom.io/download/atom-shell --build-from-source",

and running npm run rebuild.

1 Answers1

0

nodegit contains a native NodeJS module, native modules must be rebuilt to target the Electron version you use them with. Instructions for rebuilding native modules can be found at http://electron.atom.io/docs/tutorial/using-native-node-modules/

Vadim Macagon
  • 14,463
  • 2
  • 52
  • 45
  • I had already tried running `electron-rebuild`, and also tried using `npm` to install modules directly, both of which were documented in the link. They fail to solve the issue. To be clear the `nodegit` object is accessible from electron, so the module has been built. I am having a problem with promise-only operations. –  Aug 05 '16 at 14:48
  • @cynicaldevil Your problem sounds exactly like the one discussed here: https://github.com/electron/electron/issues/5851#issuecomment-224431773 so I'd suggest double checking the parameters you used for rebuilding `nodegit` to ensure they match the Electron version you're using. – Vadim Macagon Aug 05 '16 at 18:54
  • @cynicaldevil Great! Don't forget to update the target version in your NPM script when you update Electron to a different version in the future :) – Vadim Macagon Aug 06 '16 at 16:47