Require ('ffi') 在 Electron 应用程序中抛出错误
Require ('ffi') throws error in Electron application
我正在开发一个 Electron.js 应用程序,需要使用 node-ffi
模块来使用 С++ dll 库。我已经安装了模块并尝试将 require('ffi')
添加到我的 app\electron\main.dev.js
中,但出现错误:
UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The
"path" argument must be of type string. Received type object...
require('ffi')
按预期工作,例如,在这个简单的 project
中
经过一些调查我发现,错误是在 ...node_modules\bindings\bindings.js
中触发的:
exports.getRoot = function getRoot (file) {
var dir = dirname(file) // here!
file
此处未定义...
我的项目是here。
完整的错误信息:
UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The >"path" argument must be of type string. Received type object
at assertPath (path.js:39:11)
at dirname (path.js:651:5)
at Function.getRoot
(D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:482:13)
at bindings
(D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:391:32)
at Object../node_modules/ref/lib/ref.js
(D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:7148:102)
at _webpack_require__
(D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:21:30)
at Object../node_modules/ffi/lib/ffi.js
(D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:2619:11)
at _webpack_require__
(D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:21:30)
at App.<anonymous>
(D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:196:3)
at Generator.next (<anonymous>)...
这是什么魔法?
如何让 require('ffi')
在我的项目中工作?
已编辑:
... 将 internals\webpack\webpack.main.dev.js
中的 false
替换为 true
node: {
__dirname: true,
__filename: true,
},
现在错误信息是
(node:16996) UnhandledPromiseRejectionWarning: Error: Could not locate the bindings file. Tried:
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\build\binding.node
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\build\Debug\binding.node
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\build\Release\binding.node
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\out\Debug\binding.node
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\Debug\binding.node
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\out\Release\binding.node
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\Release\binding.node
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\build\default\binding.node
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\compiled.11.0\win32\ia32\binding.node
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\addon-build\release\install-root\binding.node
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\addon-build\debug\install-root\binding.node
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\addon-build\default\install-root\binding.node
тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\lib\binding\node-v69-win32-ia32\binding.node
at bindings (D:\AndrewReactElectron\ElectronReactBoilerplate4\app\electron\main.prod.js:445:9)
Any ideas?
将externals: { ffi: 'ffi' }
添加到我的webpack.main.prod.js
中解决了问题
我正在开发一个 Electron.js 应用程序,需要使用 node-ffi
模块来使用 С++ dll 库。我已经安装了模块并尝试将 require('ffi')
添加到我的 app\electron\main.dev.js
中,但出现错误:
UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object...
require('ffi')
按预期工作,例如,在这个简单的 project
经过一些调查我发现,错误是在 ...node_modules\bindings\bindings.js
中触发的:
exports.getRoot = function getRoot (file) {
var dir = dirname(file) // here!
file
此处未定义...
我的项目是here。
完整的错误信息:
UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The >"path" argument must be of type string. Received type object at assertPath (path.js:39:11) at dirname (path.js:651:5) at Function.getRoot (D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:482:13) at bindings (D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:391:32) at Object../node_modules/ref/lib/ref.js (D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:7148:102) at _webpack_require__ (D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:21:30) at Object../node_modules/ffi/lib/ffi.js (D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:2619:11) at _webpack_require__ (D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:21:30) at App.<anonymous> (D:\JavaScript\ElectronReactBoilerplate4\app\electron\main.prod.js:196:3) at Generator.next (<anonymous>)...
这是什么魔法?
如何让 require('ffi')
在我的项目中工作?
已编辑:
... 将 internals\webpack\webpack.main.dev.js
中的 false
替换为 true
node: {
__dirname: true,
__filename: true,
},
现在错误信息是
(node:16996) UnhandledPromiseRejectionWarning: Error: Could not locate the bindings file. Tried: тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\build\binding.node тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\build\Debug\binding.node тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\build\Release\binding.node тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\out\Debug\binding.node тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\Debug\binding.node тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\out\Release\binding.node тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\Release\binding.node тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\build\default\binding.node тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\compiled.11.0\win32\ia32\binding.node тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\addon-build\release\install-root\binding.node тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\addon-build\debug\install-root\binding.node тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\addon-build\default\install-root\binding.node тЖТ D:\AndrewReactElectron\ElectronReactBoilerplate4\app\lib\binding\node-v69-win32-ia32\binding.node at bindings (D:\AndrewReactElectron\ElectronReactBoilerplate4\app\electron\main.prod.js:445:9)
Any ideas?
将externals: { ffi: 'ffi' }
添加到我的webpack.main.prod.js
中解决了问题