我将 node-webkit 与一个名为 edge 的外部模块一起使用.
根据 node-webkit 文档,包含 native 代码的模块必须使用 nw-gyp
重新编译,而不是 node-gyp
。我能够在没有错误的情况下重新编译,node-webkit 似乎可以导入模块。
这是我的代码。我尝试使用的代码:
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);
});
在 node-webkit 中运行时抛出以下错误。
Uncaught TypeError: Object [object Object] has no method 'func'
如果将对象写入 console.log
我可以看到:
Object {initializeClrFunc: function}
initializeClrFunc: function () { [native code] }
__proto__: Object
所以模块似乎已经加载了。如果我在 node-webkit 之外运行相同的代码,一切正常,我可以访问 func
函数。这让我发疯 - 非常感谢任何帮助。
最佳答案
func
方法由 edge.js
提供,它是 edge.node
原生模块的包装器。因此,您应该将 require('edge.node')
替换为 require('edge')
。
关于node.js - 带有包含 native 代码的外部模块的 Node-Webkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16920758/