【问题标题】:Nodegit and Electron not working togetherNodegit 和 Electron 不能一起工作
【发布时间】:2017-01-29 19:05:21
【问题描述】:

我在使用 nodegit 时遇到此错误,我不确定是否是我不知道如何使用电子遥控器的错,还是 nodegit 的问题。为了以防万一,我做了file an issue

在我的 main.js 电子文件中,我可以毫无问题地使用 nodegit。

在网站上,我尝试使用带有remote 的nodegit。我得到一个错误。我的代码:

var remote = require('electron').remote;
var pathToRepo = remote.require('path').resolve(currentRepoDir);
remote.require('nodegit').Repository.open(pathToRepo).then(function(repo){
  console.log(repo);
}); 

我收到错误:

Uncaught TypeError: require(...).remote.require(...).Repository.open is not a function

为什么open 不是函数?

【问题讨论】:

  • 你为什么要使用remoteremote module 本质上使用 RMI,它存在许多缺点,通常不需要。是否有特殊原因不需要直接使用“path”和“nodegit”,而不需要远程?
  • @inukshuk 我会尝试更新问题。 remote 的用例是什么?
  • 在我看来,remote 的主要用例是当您需要访问一些仅对主进程可用的 Electron 模块(例如,remote.app)时——有无法直接在您的渲染器进程中要求这些。但是节点模块是可用的,所以我真的没有理由在主进程中创建它们并通过 RMI 访问它们,除非你想以某种方式在进程之间共享状态。

标签: javascript node.js electron nodegit


【解决方案1】:

你为什么使用remote.require

remote.require('path')

只需使用:

require('path')

require 也适用于渲染过程。

【讨论】:

    猜你喜欢
    • 2014-01-07
    • 2019-08-17
    • 2016-11-23
    • 2019-02-18
    • 2015-05-16
    • 2017-10-14
    • 2012-06-01
    • 2011-11-05
    • 2018-05-20
    相关资源
    最近更新 更多