首页 > 开发 > JS > 正文

关于node-bindings无法在Electron中使用的解决办法

2024-05-06 16:47:08
字体:
来源:转载
供稿:网友

node-bindings非常好用,但是在Electron中无法使用,我查了一下,是因为fileName以file://开头导致无法定位动态库的根目录。已经提交给作者了,可以临时修改一下node_modules/bindings/bindings.js。

exports.getFileName = function getFileName (calling_file) { var origPST = Error.prepareStackTrace  , origSTL = Error.stackTraceLimit  , dummy = {}  , fileName Error.stackTraceLimit = 10 Error.prepareStackTrace = function (e, st) {  for (var i=0, l=st.length; i<l; i++) {   fileName = st[i].getFileName()   if (fileName !== __filename) {    if (calling_file) {      if (fileName !== calling_file) {       return      }    } else {     return    }   }  } } // run the 'prepareStackTrace' function above Error.captureStackTrace(dummy) dummy.stack // cleanup Error.prepareStackTrace = origPST Error.stackTraceLimit = origSTL //In Electron, filename starts with "file://" var fileSchema = "file://"; if(fileName.indexOf(fileSchema) === 0) {   fileName = fileName.substr(fileSchema.length);   //on windows   if(fileName.indexOf(":/") == 2){     fileName = fileName.substr(1);   } } return fileName}

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对VeVb武林网的支持。


注:相关教程知识阅读请移步到JavaScript/Ajax教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表