带有包含本机代码的外部模块的Node-Webkit

时间:2021-12-05 05:40:40

I'm using node-webkit with an external module called edge.

我正在使用node-webkit和一个名为edge的外部模块。

According to the node-webkit docs modules that contain native code must be recompiled using nw-gyp as oppose to node-gyp. I was able to recompile without error and node-webkit seems to import the module OK.

根据node-webkit docs,包含本机代码的模块必须使用nw-gyp重新编译,与node-gyp相反。我能够无错误地重新编译,node-webkit似乎导入模块OK。

Heres my code. The code I'm trying to use:

继承我的代码。我正在尝试使用的代码:

var edge = require('edge.node');

var hello = edge.func(function () {/*
async (input) => 
{ 
    return ".NET welcomes " + input.ToString(); 
}
*/});

hello('Node.js', function (error, result) {
if (error) throw error;
console.log(result);
});

Which throws the following error when run within node-webkit.

在node-webkit中运行时会引发以下错误。

Uncaught TypeError: Object [object Object] has no method 'func' 

If write the object out to console.log I can see:

如果将对象写入console.log,我可以看到:

 Object {initializeClrFunc: function}
 initializeClrFunc: function () { [native code] }
 __proto__: Object

So the module seems to have loaded. If I run the same code outside of node-webkit, everything works perfectly and I can access the func function. This is driving me crazy - and any help would be really appreciated.

所以该模块似乎已经加载。如果我在node-webkit之外运行相同的代码,一切都很完美,我可以访问func函数。这让我发疯了 - 任何帮助都会非常感激。

1 个解决方案

#1


0  

func method is provided by edge.js, the wrapper around edge.node native module. So you should replace require('edge.node') by require('edge').

func方法由edge.js提供,是edge.node本机模块的包装器。所以你应该用require('edge')替换require('edge.node')。

#1


0  

func method is provided by edge.js, the wrapper around edge.node native module. So you should replace require('edge.node') by require('edge').

func方法由edge.js提供,是edge.node本机模块的包装器。所以你应该用require('edge')替换require('edge.node')。