我使用 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']
}
}
}
最佳答案
很可能您正在尝试将方法“indexOf”应用于尚 undefined variable 。查看文档 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf .检查您的变量是否在某处定义,它应该是数组类型。
关于vue.js - 错误 "Cannot read property ' indexOf' of undefined"绑定(bind) n-api 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59875609/