Error: Could not locate the bindings file. Tried:

Error: Could not locate the bindings file. Tried:

我 运行 在尝试 运行 我的包含我的 Express 应用程序的电子应用程序时遇到以下错误。

Error: Could not locate the bindings file. Tried:

我认为问题与 serialport 模块有关,因为不需要它一切正常。

C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\bindings\bindings.js:91

<br>Error: Could not locate the bindings file. Tried:
<br> → C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\serialport\build\serialport.node
<br> → C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\serialport\build\Debug\serialport.node
<br> → C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\serialport\build\Release\serialport.node
<br> → C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\serialport\out\Debug\serialport.node
<br> → C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\serialport\Debug\serialport.node
<br> → C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\serialport\out\Release\serialport.node
<br> → C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\serialport\Release\serialport.node
<br> → C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\serialport\build\default\serialport.node
<br> → C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\serialport\compiled.3.1\win32\ia32\serialport.node
<br>    at bindings (C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\bindings\bindings.js:88:9)
<br>    at Object.<anonymous> (C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\serialport\lib\bindings.js:3:35)
<br></anonymous>    at Module._compile (module.js:541:32)
<br>    at Object.Module._extensions..js (module.js:550:10)
<br>    at Module.load (module.js:458:32)
<br>    at tryModuleLoad (module.js:417:12)
<br>    at Function.Module._load (module.js:409:3)
<br>    at Module.require (module.js:468:17)
<br>    at require (internal/module.js:20:19)
<br>    at Object.<anonymous> (C:\Users\Jonathan\Desktop\client\<NAME>\electron-with-express\express-app\node_modules\serialport\lib\serialport.js:15:25)

您需要重建串口模块,因为它使用与 Electron 不同的 V8 头文件。

首先您需要设置一个 node-gyp 工具链 (https://github.com/nodejs/node-gyp)

接下来,安装任意版本的Visual Studio。

打开命令 window 并将目录更改为项目中的 node_modules/serialport。

使用适当的变量输入此命令:

node-gyp rebuild --target=<electron_version> --arch=<arch> --dist-url="https://atom.io/download/atom-shell" --msvs_version=<visual_studio_year>

例如,这是我在重建时使用的命令:

node-gyp rebuild --target=1.2.5 --arch=x64 --dist-url="https://atom.io/download/atom-shell" --msvs_version=2013

我遇到了类似的问题。我的解决方案:我更具体地了解了我使用的是哪个版本的 nodejs。我有最新版本(在撰写本文时)13.8,我遇到了与 OP 相同的问题。

所以我安装了 nvm 并开始使用它来选择我的 nodejs。

$ nvm install --lts 
$ nvm use --lts
Now using node v12.16.0

当前的长期支持版本(在撰写本文时)是 12.6。我为应用程序重做了 npm install,之后我的串口就没有问题了。从理论上讲,我本可以一直使用 nvm 安装不同版本的 nodejs,直到我得到一个有效的版本。

在通过 Dependabot 和 运行 npm audit fix.

合并包更新后,我遇到了一个 Could not locate the bindings file 错误

我的修复是 运行 npm ci.