执行 npm run start命令时报错:
PS D:\work_dir\XXX\13_STYG\fanuc-cnc> npm run start
> fanuc-cnc-test@1.0.0 start
> node index.js
> node index.js
> node index.js
D:\work_dir\XXX\13_STYG\fanuc-cnc\node_modules\ffi-napi\lib\dynamic_library.js:75
throw new Error('Dynamic Linking Error: ' + err);
^
Error: Dynamic Linking Error: Win32 error 193
at new DynamicLibrary (D:\work_dir\xxx\13_STYG\fanuc-cnc\node_modules\ffi-napi\lib\dynamic_library.js:75:11)
at new Library (D:\work_dir\xxx\13_STYG\fanuc-cnc\node_modules\ffi-napi\lib\library.js:47:10)
at Object.<anonymous> (D:\work_dir\xxx\13_STYG\fanuc-cnc\index.js:18:15)
at Module._compile (node:internal/modules/cjs/loader:1198:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
at Module.load (node:internal/modules/cjs/loader:1076:32)
at Function.Module._load (node:internal/modules/cjs/loader:911:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47
原因:Node的版本是64位的,但是dll文件是32位的。
解决办法一:
1、下载 32 位版本的 Node.js,根据安装向导完成Nodejs的安装。
2、删除项目中的node_modules文件夹。
3、重新安装整个项目的依赖(npm install)。
4、再次运行程序测试能否成功调用dll文件。
PS D:\work_dir\gdi\13_STYG\fanuc-cnc> npm run start
> fanuc-cnc-test@1.0.0 start
> node index.js
成功连接到 CNC
CNC 系统信息: { '类型': 1634, '机床类型': 32, '系列': 12320, '版本': 21536, '轴数': 13892 }
解决办法二:
重新生成64位版本的DLL文件或者换成64位版本的DLL文件,然后重新运行程序测试能否成功调用。