[英]Runing nodegit in Electron fails
I installed nodegit 0.26.5
via npm
and import the package in the renderer part of my Electron application.我通过
npm
安装了nodegit 0.26.5
,并在我的 Electron 应用程序的渲染器部分中导入了 package。 During compilation I receive this error below:在编译期间,我收到以下错误:
WARNING in ./node_modules/nodegit/dist/nodegit.js
Module not found: Error: Can't resolve '../build/Release/nodegit.node' in '/Users/steve/Documents/git/git_reader/node_modules/nodegit/dist'
ERROR in ./node_modules/nodegit/dist/nodegit.js
Module not found: Error: Can't resolve '../build/Debug/nodegit.node' in '/Users/steve/Documents/git/git_reader/node_modules/nodegit/dist'
ERROR in ./node_modules/nodegit/dist/nodegit.js
Module not found: Error: Can't resolve '../package' in '/Users/steve/Documents/git/git_reader/node_modules/nodegit/dist'
In my node_modules/nodegit/build
directory, I only have a Release
directory.在我的
node_modules/nodegit/build
目录中,我只有一个Release
目录。 Does anyone have an idea what I miss here?有人知道我在这里想念什么吗?
I created a repo, which I forked from a boilerplate template.我创建了一个 repo,它是从样板模板中派生出来的。 I only added
nodegit
and @types/nodegit
as a dependency and imported it in details.component.ts
我只添加了
nodegit
和@types/nodegit
作为依赖项并将其导入details.component.ts
https://github.com/Githubber2021/electron-nodegit-error https://github.com/Githubber2021/electron-nodegit-error
git clone https://github.com/Githubber2021/electron-nodegit-error.git
npm install
npm run electron:local
to reproduce the issue.重现问题。 Can anyone reproduce the error on their machine?
任何人都可以在他们的机器上重现错误吗? What am I missing here?
我在这里想念什么? Thank you so much for any help or hint!!
非常感谢您的任何帮助或提示!
I'm using nodegit 0.27
and the error message for me was slightly different, it was我正在使用
nodegit 0.27
,我的错误消息略有不同,它是
nodegit.js:1088 Uncaught Error: Cannot find module '../package'
Note that I'm using webpack together with electron forge and in my package.json I have the following.请注意,我正在使用 webpack 和 electron 锻造,并且在我的 package.Z466DEEC76ECDF5FCA6DZ3871 中有以下内容。 (I replaced the irrelevant parts with
...
) (我用
...
替换了不相关的部分)
{
"name": ...
"version": ...
"description": ...
"config": {
"forge": {
"packagerConfig": {},
"makers": [
...
],
"plugins": [
[
"@electron-forge/plugin-webpack",
{
"mainConfig": ...
"renderer": {
"config": "./webpack.renderer.config.js",
"entryPoints": [
...
]
}
}
]
]
}
},
...
}
And in my webpack.renderer.config.js
I needed to add an externals
field to my exports so that they look something like this在我的
webpack.renderer.config.js
中,我需要在导出中添加一个externals
字段,以便它们看起来像这样
module.exports = {
...
externals: {
nodegit: 'commonjs nodegit'
},
};
Then in my main.ts
, the main process I have然后在我的
main.ts
中,我的主要过程
(global as any).mynodegit = require('nodegit');
And then I use IPC to access nodegit within my renderer process.然后我使用 IPC 在我的渲染器进程中访问 nodegit。 Note that the
@ts-ignore
is required to suppress error messages from typescript.请注意,需要
@ts-ignore
来抑制来自 typescript 的错误消息。
import { remote } from "electron";
// @ts-ignore
import * as Git from "@types/nodegit";
// @ts-ignore
const Git = remote.getGlobal('mynodegit');
Here is the boilerplate that helped me with this https://github.com/newblord/electron-react-webpack-nodegit-boilerplate这是帮助我完成https://github.com/newblord/electron-react-webpack-nodegit-boilerplate的样板
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.