How to get nodegit working with electron-forge?

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:

  1. my-app-ef $ nvm use
  2. nodegit $ npm install
  3. nodegit $ BUILD_ONLY=true npm link
  4. 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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật