nodegit: Module not found: Error: Can't resolve '../build/Debug/nodegit.node'
I am getting these errors when using this library
The Debug
folder isn’t even there. Anyone have any idea?
I am using Node 6.10.2
and npm 3.10.10
:
ERROR in ./~/nodegit/dist/nodegit.js
Module not found: Error: Can't resolve '../package' in 'C:\Users\Dolan\Documents\Git-Proton\node_modules\nodegit\dist'
@ ./~/nodegit/dist/nodegit.js 979:18-39
@ ./src/app/common/git/git.service.ts
@ ./src/app/common/git/git.module.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi ./src/main.ts
ERROR in ./~/nodegit/dist/nodegit.js
Module not found: Error: Can't resolve '../build/Debug/nodegit.node' in 'C:\Users\Dolan\Documents\Git-Proton\node_modules\nodegit\dist'
@ ./~/nodegit/dist/nodegit.js 18:11-49
@ ./src/app/common/git/git.service.ts
@ ./src/app/common/git/git.module.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi ./src/main.ts
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 7
- Comments: 25
Commits related to this issue
- Use IgnorePlugin to ignore missing .node file (https://github.com/nodegit/nodegit/issues/1335#issuecomment-778636902) — committed to lonelyshore/intergitive by zedaizd 3 years ago
Having the same issue in Mac OSX 10.12.6, using Electron. Log:
I also encountered this error message when using webpack to pack up (not during run-time though).
I figured out that commenting out the line importing debug version of
nodegit.node
helps webpack bundle successfully.But I wonder what is the purpose of loading debug version of
nodegit.node
and if it is the right thing to ignore it in webpack.Project Configuration
Here is part of my package.json:
Not sure if it matters, my node version is 12.20 and I installed nodegit with prebuilt binaries targeting windows x64.
You may see that I installed
electron
,webpack
, and a package namednode-loader
. The usage of the last package will be explained later.And here is my webpack configuration for the main process of electron:
I
require('nodegit');
inmain.js
to forcewebpack
to bundle it to test if it can be bundled successfully for main process of electron.Problem Description
Before the
node-loader
package is installed,webpack
fails to pack release version ofnodegit.node
with the following error message:Because line 12 of
nodegit.js
is actually catched, this exception further leads to another exception when trying to load debug version ofnodegit.node
:Here the
node-loader
comes to rescue.Since
webpack
told me to search for loaders to solve the error for release version ofnodegit.node
, I installednode-loader
.It eliminates the first error message but the second one continues to show.
Since there is no debug version, currently what I could do is commenting out
rawApi = require("../build/Debug/nodegit.node");
.After doing so,
webpack
could finally bundlenodegit
and it finally works. (launched the bundled JS with electron)Hope this help everyone trying to use nodegit together with electron and webpack.
Edit 1
As it would be better to instruct webpack to ignore unused
require
instead of modifying source of nodegit, I spent some time on figuring it out. One solution is that one may useIgnorePlugin
to do so. Adding the lineplugins: [ new IgnorePlugin(/build\/Debug\/nodegit.node/i) ]
to mywebpack
config solves the problemEdit 2
Eventually I have to add
nodegit
intoexternals
in my webpack configuration to build in production mode. I can build my project with webpack successfully now so please one take its webpack.config.js as a working example. I hope it helps.I got this to work with Electron by attaching it to the
window
from thepreload.js
instead of requiring it from a rendering thread:preload.js:
electron.js:
From the rest of the application I then access it from
window.NodeGit
.I’ve only recently picked up Electron, so I’m not really well known yet with process specific issues. I’ll take a look when I’m home and see if I can somehow solve the issue or provide some more information.