0

I'm working on an open source electron project which I am building using webpack. One requirement for my project is to use the nodegit library which has to be built as a native module.

I've followed what appears to be conventional advice when working with native modules and electron. That is, I run electron-rebuild, have configured the source package to use and finally have configured node-loader to catch the import of any .node files.

Unfortunately, when I go to include the module, I end up with this error:

ERROR in ./node_modules/nodegit/dist/nodegit.js
 Module not found: Error: Can't resolve '../build/Debug/nodegit.node' in 
 'C:\Users\atrauzzi\Development\atrauzzi\gerty\node_modules\nodegit\dist'
  @ ./node_modules/nodegit/dist/nodegit.js 18:11-49
  @ ./src/Layer/Domain/Thunktor/Git/CloneGitRepository.ts
  @ ./src/Layer/Gerty/Component/Repository/AddGitHubRepository.tsx
  @ ./src/Layer/Gerty/Component/Repository/AddRepository.tsx
  @ ./src/Layer/Gerty/Component/Workspace.tsx
  @ ./src/Layer/Gerty/Component/App.tsx
  @ ./src/Layer/Gerty/GertyServiceProvider.ts
  @ ./src/Bundle/GertyElectron.ts

The only thing I can see that's suspicious at this point is that when I rebuild the module to work with electron, I only get a Release directory, when the import seems to be looking for Debug:

enter image description here

This could be a red herring however as nodegit is written to try Debug as a fallback after Release has failed.

The general ask here is "How do I get this native module working in my project?".

I also have a corresponding question over at the repo, although on the off chance that my issue is unrelated to the library itself, or that there are some battle-worn veterans of native modules in electron, I figured SO would be a good place to check as well.

Alexander Trauzzi
  • 7,277
  • 13
  • 68
  • 112

1 Answers1

0

Try configuring your webpack by specifying the native module as an external dependancy rather than load it using the node-loader.

https://webpack.js.org/configuration/externals/

shashi
  • 4,616
  • 9
  • 50
  • 77