electron打包 Error output: !include: could not find:
Error output:
2 !include: could not find: "C:\Users\xxxx(这里是中文)\AppData\Local\Temp\t-TH3KzB\0-messages.nsh"
3 Error in script "<stdin>" on line 75 -- aborting creation process
这个报错意思是路径有中文存在,解析不到,完整的错误显示如下:
Error output:
!include: could not find: “C:\Users\xxxx(这里是中文)\AppData\Local\Temp\t-TH3KzB\0-messages.nsh”
Error in script “” on line 75 – aborting creation process
at ChildProcess.<anonymous> (D:\electron-learing\electron-record-learn\record-project\node_modules\builder-util\src\util.ts:250:14)
at Object.onceWrapper (node:events:642:26) s\builder-util\src\util.ts:250:14)
at ChildProcess.emit (node:events:527:28)
at ChildProcess.cp.emit (D:\electron-learing\electron-record-learn\record-project\node_modules\cross-spawn\lib\enoent.js:34:29)
at maybeClose (node:internal/child_process:1092:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5) {
exitCode: 1,
alreadyLogged: false,
code: ‘ERR_ELECTRON_BUILDER_CANNOT_EXECUTE’
}
把编译出来的乱码用utf-8来编译:
找到 node_module/app-builder-lib/out/targets/nsis/NsisTarget.js文件,在 executeMakensis 方法中加入相应的代码,
async executeMakensis(defines, commands, script) {
const args = this.options.warningsAsErrors === false ? [] : ["-WX"];
//添加下面这一行即可
args.push("-INPUTCHARSET", "UTF8");
for (const name of Object.keys(defines)) {
const value = defines[name];
if (value == null) {
args.push(`-D${name}`);
} else {
args.push(`-D${name}=${value}`);
}
}
}