I’m building an Electron app (on MacOS) and want to use nodegit. The app is a typical electron-forge app, built with the “webpack-typescript” template.
nodegit’s docs say it should just work, but it does not, so I’ve had to resort to building nodegit from source. That part works:
my-app-ef $ nvm use
nodegit $ npm install
nodegit $ BUILD_ONLY=true npm link
my-app-ef $ npm link nodegit
I do all this from a single terminal so that steps 2-4 honor my-app’s .nvmrc
. I also do it from iTerm2 instead of VSCode’s integrated terminal, because reasons.
All of that succeeds. The last two steps take about 3 minutes each, but are very quiet and only emit success messages.
Inspecting the filesystem seems to confirm there is a built version of nodegit at my-app-ef/node_modules/nodegit
(which is a symlink to my local clone of nodegit). For example, this file exists: my-app-ef/node_modules/nodegit/build/Release/nodegit.node
But, there is nothing at my-app-ef/node_modules/.bin/nodegit
, which is where I’d expect a binary dependency to appear.
And I can’t import my nodegit at runtime:
// src/main/my-app.ts
import NodeGit from 'nodegit'
When I run my app, I get this error right away:
App threw an error during load
Error: Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
at ../nodegit/build/Release/nodegit.node (/Users/tom/projects/my-app-ef/.webpack/main/index.js:23086:7)
at __webpack_require__ (/Users/tom/projects/my-app-ef/.webpack/main/index.js:31019:42)
at ../nodegit/lib/nodegit.js (/Users/tom/projects/my-app-ef/.webpack/main/index.js:25580:12)
at __webpack_require__ (/Users/tom/projects/my-app-ef/.webpack/main/index.js:31019:42)
at ./src/main/my-app.ts (/Users/tom/projects/my-app-ef/.webpack/main/index.js:22748:17)
at __webpack_require__ (/Users/tom/projects/my-app-ef/.webpack/main/index.js:31019:42)
at /Users/tom/projects/my-app-ef/.webpack/main/index.js:31052:37
at Object.<anonymous> (/Users/tom/projects/my-app-ef/.webpack/main/index.js:31055:12)
at Module._compile (node:internal/modules/cjs/loader:1271:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1326:10)
I gather that this is webpack saying it finds something unintelligible when it tries to resolve the 'nodegit'
dependency, but I thought npm link
was supposed to sort that out for me.
Also, I assume that since the nodegit process involves gcc, my nodegit build should be a binary file, not some text files filled with JS code. So I would not expect to run into webpack problems, because this dependency can’t go through transpilation (and doesn’t need it). I figure this is related to the missing node_modules/.bin/nodegit
, but I don’t know how to resolve that.
The rest of my app builds and runs fine with no errors if I stop importing nodegit.
Any help is appreciated.
- node v22.7.0
- electron-forge 5.2.4