node.js - 选举:ffi_bindings.node 不是有效的 Win32 应用程序
问题描述
在使用 electron-builder 构建我的 Windows 应用程序后,ffi_napi 显然已正确重建和打包:
但是当我尝试执行 Windows 应用程序时,我得到:
我在模块上遇到了类似的问题canvas
,但我使用这个特定的代码解决了这个问题,该代码将修补节点 abi 的版本以使用来自电子的版本。但是,自从我添加ffi_napi
后,无论是否使用此 hack,该应用程序现在都无法正常工作。
/* eslint-disable @typescript-eslint/no-var-requires */
const { promises: fs } = require('fs')
const path = require('path')
const {
get_runtime_abi: getRuntimeAbi,
} = require('../../node_modules/node-pre-gyp/lib/util/versioning')
const blue = '\u001b[36m'
const yellow = '\u001b[33m'
const red = '\u001b[31m'
const nc = '\u001b[0m'
const info = text => console.warn(blue + text + nc)
const warn = text => console.warn(yellow + text + nc)
const error = text => console.warn(red + text + nc)
const versioningPath = path.resolve(
__dirname,
'..',
'..',
'node_modules',
'node-pre-gyp',
'lib',
'util',
'versioning.js'
)
const nodeAbi = getRuntimeAbi('node')
const originalNodeAbi = 'node_abi: get_runtime_abi(runtime,options.target)'
const originalNodeNapiLabel =
"node_napi_label: napi_build_version ? 'napi-v' + napi_build_version : get_runtime_abi(runtime,options.target)"
const replacedNodeAbi = `node_abi: '${nodeAbi}'`
const replacedNodeNapiLabel = `node_napi_label: '${nodeAbi}'`
async function preBuild() {
const versioning = await fs.readFile(versioningPath, 'utf8')
const versioningNodeNapiLabel = versioning.replace(
originalNodeNapiLabel,
replacedNodeNapiLabel
)
const versioningNodeAbi = versioningNodeNapiLabel.replace(
originalNodeAbi,
replacedNodeAbi
)
if (versioning === versioningNodeNapiLabel) {
warn("Electron pre-build: node_napi_label hasn't been replaced")
}
if (versioning === versioningNodeAbi) {
error("Electron pre-build: node_abi hasn't been replaced")
} else {
await fs.writeFile(versioningPath, versioningNodeAbi, 'utf8')
info('Electron pre-build successfully executed')
}
}
async function postBuild() {
let versioning = await fs.readFile(versioningPath, 'utf8')
versioning = versioning.replace(replacedNodeAbi, originalNodeAbi)
versioning = versioning.replace(replacedNodeNapiLabel, originalNodeNapiLabel)
await fs.writeFile(versioningPath, versioning, 'utf8')
info('Electron post-build successfully executed')
}
module.exports = { preBuild, postBuild }
解决方案
推荐阅读
- c# - 使用 C# 9 记录添加评论的正确方法是什么?
- swift - 快速接受任何类型测量的函数
- r - 使用 position_jitterdodge 对多面图中的点进行子集化
- sql - SQL:如何使用 group by 从一个表中选择不在另一个表中的行?
- serenity-platform - 在字段更改时在运行时验证字段
- python - 为单链表实现查找节点功能
- r - 在 R 中并行化一个重要的 Gibbs 采样器:RcppThread 与 RcppParallel
- asp.net-mvc - Razor 页面路由在 MVC 应用程序中不起作用
- r - 如何满足R中幼苗存活数据的Cox比例风险模型假设
- c# - 使用 TopShelf 的 Windows 服务:底层提供程序在打开时失败。用户登录失败