Electron 在打包应用程序时出现 Reactjs execFile 错误
Electron with Reactjs execFile error when packing the app
我使用 var child = require("child_process").execFile;
来 运行 外部 .exe 文件。当我 运行 应用程序处于调试模式时,一切 运行 都很顺利。当我构建并打包应用程序时,它会抛出以下错误。
未捕获类型错误:(0 , a(...).execFile) 不是函数
我的代码:
var path = require("path");
export function silentPrintPDF(htmlString) {
var child = require("child_process").execFile;
var executablePath = path.join(
__dirname,
"extraResources",
"ElectronPrinter.exe"
);
var parameters = [htmlString];
child(executablePath, parameters, function(err, data) {
console.log(err);
console.log(data.toString());
});
}
我使用以下命令打包应用程序:
"electron:pack": "yarn build && electron-builder build -w"
根据我的评论,答案最终是使用 window.require
来防止混淆 Electoron 的要求和 Browserify 的要求。
我使用 var child = require("child_process").execFile;
来 运行 外部 .exe 文件。当我 运行 应用程序处于调试模式时,一切 运行 都很顺利。当我构建并打包应用程序时,它会抛出以下错误。
未捕获类型错误:(0 , a(...).execFile) 不是函数
我的代码:
var path = require("path");
export function silentPrintPDF(htmlString) {
var child = require("child_process").execFile;
var executablePath = path.join(
__dirname,
"extraResources",
"ElectronPrinter.exe"
);
var parameters = [htmlString];
child(executablePath, parameters, function(err, data) {
console.log(err);
console.log(data.toString());
});
}
我使用以下命令打包应用程序: "electron:pack": "yarn build && electron-builder build -w"
根据我的评论,答案最终是使用 window.require
来防止混淆 Electoron 的要求和 Browserify 的要求。