我用n-api编写了一个c++模块,用cmake-js编译了它,现在我想在我的electron-vue应用程序中使用它。如果我在没有electron-vue的项目中使用这个模块,它可以工作。但是当我尝试在我的electron-vue应用程序中使用它时,我总是得到这样的错误:
App threw an error during load
TypeError: Cannot read property 'indexOf' of undefined
at Function.getFileName (D:\temp\test2\node_modules\bindings\bindings.js:178:16)
at bindings (D:\temp\test2\node_modules\bindings\bindings.js:82:48)
at eval (webpack:///./src/main/index.js?:28:67)
at Module../src/main/index.js (D:\temp\test2\dist\electron\main.js:3822:1)
at __webpack_require__ (D:\temp\test2\dist\electron\main.js:21:30)
at eval (webpack:///./src/main/index.dev.js?:11:1)
at Object../src/main/index.dev.js (D:\temp\test2\dist\electron\main.js:3810:1)
at __webpack_require__ (D:\temp\test2\dist\electron\main.js:21:30)
at eval (webpack:///multi_./src/main/index.dev.js_./src/main/index.js?:1:1)
at Object.0 (D:\temp\test2\dist\electron\main.js:3880:1)我是这样使用bindings的:
const colorBalance = require('bindings')('colorBalance');我试图根据this将我的模块定义为外部模块,但它没有解决问题:
// vue.config.js
module.exports = {
pluginOptions: {
electronBuilder: {
externals: ['NameOfMyModule']
}
}
}发布于 2020-01-23 18:13:44
很可能您正在尝试将方法'indexOf‘应用于尚未定义的变量。看看docs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf吧。检查您的变量是否在某处定义,并且它应该是数组类型。
发布于 2020-01-25 22:30:25
同时,我尝试在不使用bindings的情况下导入模块
const colorBalance = require('../../build/Release/colorBalance.node');然后我得到了一个新的错误:
Error: Cannot open D:\temp\test2\build\Release\colorBalance.node: Error: Module did not self-register.
at Object.eval (webpack:///./build/Release/colorBalance.node?:1:155)
at eval (webpack:///./build/Release/colorBalance.node?:2:30)
at Object../build/Release/colorBalance.node (D:\temp\test2\dist\electron\main.js:97:1)
at __webpack_require__ (D:\temp\test2\dist\electron\main.js:21:30)
at eval (webpack:///./src/main/index.js?:28:20)
at Module../src/main/index.js (D:\temp\test2\dist\electron\main.js:3833:1)
at __webpack_require__ (D:\temp\test2\dist\electron\main.js:21:30)
at eval (webpack:///./src/main/index.dev.js?:11:1)
at Object../src/main/index.dev.js (D:\temp\test2\dist\electron\main.js:3821:1)
at __webpack_require__ (D:\temp\test2\dist\electron\main.js:21:30)我用electron-rebuild重建了电子。我读过关于win_delay_load_hook here的文章,也尝试过this,但错误并没有消失。
发布于 2020-01-26 17:23:17
我已经通过将构建链从cmake更改为gyp解决了我的问题。使用gyp编译一切正常。
https://stackoverflow.com/questions/59875609
复制相似问题