温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-08-29 22:20:13 来源:脚本之家 阅读:352 作者:李先静 栏目:web开发

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
}

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对亿速云的支持。如果你想了解更多相关内容请查看下面相关链接

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI