我正在使用 electron 和 vue 构建桌面应用程序,一切正常,在开发模式下运行该应用程序并通过运行
electron:build
构建它直到最后一个构建,但我不断收到 Octal escape sequences. 的错误
我很确定它必须处理
strict mode
,但我试图找到八进制转义但没有机会,我试图删除一些我在上次成功构建后添加的无用依赖项也没有用
PS:electron:serve 工作正常
错误的图片
background.js 来自 Terser 模板字符串中不允许使用八进制转义序列 [background.js:1026,68555]
ERROR 构建因错误而失败。 错误!代码生命周期 错误!错误号 1 错误!键盘管理@0.1.0 电子:构建:
错误!退出状态 1 错误! 错误!在 [email protected] electron:build 脚本中失败。 错误!这可能不是 npm 的问题。上面可能有额外的日志输出。vue-cli-service electron:build
问题出在background.js。在第 1026 行和第 68555 行中,查找其中包含八进制序列的模板字符串。例子:
console.log(`Octal sequences like \033 are not allowed here`)
您可以将 es6 模板恢复为(常规)字符串:
console.log("Octal sequences like \033 are allowed here")
或者您可以尝试 不同的、允许的编码,例如,
console.log(`Sequences like \2264 are not allowed here`);
console.log(`But sequences like \u2264 are allowed`);
抱歉,这是一个相当晚的回复,但实际上有一种方法可以在模板字符串中使用八进制转义序列。您使用其中的普通字符串添加八进制序列。例如:
let myString = `foo ${"\033"} bar`
这类似于将字符串加在一起:
let myString = `foo ` + "\003" + ` bar`
console.log(String.raw `Octal sequences like \033 are not allowed here`)
我在 Typescript 和
strict
模式下尝试更改终端输出时来到这里。以上答案都没有真正涵盖它。
原始Javascript模板字符串使用八进制转义
\033
:
`${info.timestamp} [${info.level}] \033[35m${info.label}\033[39m: ${info.message}`
但是,这些在严格模式下已被弃用。所以解决方案是改为转换为十六进制转义序列: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal
这意味着你必须进行八进制到十六进制的转换,并将
\033
变成 \x1B
,如下所示:
`${info.timestamp} [${info.level}] \x1B[35m${info.label}\x1B[39m: ${info.message}`
这样,本例中
info.label
的输出在终端窗口中按预期进行颜色编码。
如果您在 Windows 上,请将反斜杠更改为正斜杠
正如 ES2016 行为部分中所指出的,八进制字符串在由
\0o
而不是 \0
启动时工作正常:
这确实不工作:
console.log(`\033]0;Some title\007`);
但这确实:
console.log(`\0o33]0;Some title\0o07`);
并具有设置终端标题的预期效果。