vue.js - 错误 "Cannot read property ' indexOf' of undefined"绑定(bind) n-api 模块

标签 vue.js cmake electron n-api

我使用 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/

相关文章:

css - Vuejs 从顶部导航栏中删除滚动条

vue.js - 在 VueJs 中处理大数据

c++ - “Cannot find -l<directory>”错误-CMake

javascript - Webpack错误: please install sqlite3 package manually

javascript - 如何让 ReactJS JSX 在 Electron 上工作

node.js - RecordRTC:间隔上传到Web服务器的视频文件无法播放

javascript - 阻止在 vue.js 中输入某些数字

javascript - 如何减少 WEBPACK + VUEJS 中的包大小

Android NDK CMake 链接问题

c++ - 如何在 C++ 源代码中读取 CMake 变量