You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 10运行Electron入门教程时控制台输出编码乱码求助

Electron控制台Emoji在PowerShell显示乱码的解决办法

问题详情

在Windows 10系统的VS Code中进行Electron入门开发,编写的main.js代码如下:

console.log('Hello from Electron 👋')

预期在PowerShell窗口输出Hello from Electron 👋,但实际显示为Hello from Electron ≡ƒæï。已确认VS Code编码设置为UTF-8,且尝试更换过PowerShell字体,问题仍未解决。

可行解决方案

1. 切换PowerShell代码页为UTF-8

PowerShell默认代码页不支持UTF-8 emoji显示,执行以下命令临时切换:

chcp 65001

若需永久生效,可修改注册表:

  • 打开注册表编辑器(运行regedit)
  • 定位到HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor
  • 新建字符串值Autorun,设置值为chcp 65001,重启PowerShell后生效。

2. 配置PowerShell输出编码为UTF-8

在PowerShell中执行命令临时设置:

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

永久生效则添加到PowerShell配置文件:

  • 运行notepad $PROFILE打开配置文件(文件不存在则执行New-Item -Path $PROFILE -ItemType File -Force创建)
  • 写入[Console]::OutputEncoding = [System.Text.Encoding]::UTF8,保存后重启PowerShell。

3. 确保Electron输出编码为UTF-8

修改main.js,显式指定输出编码:

process.stdout.setEncoding('utf8');
console.log('Hello from Electron 👋');

或者在启动Electron前,在PowerShell中设置环境变量:

$env:PYTHONIOENCODING="utf-8"

再执行项目启动命令(如npm start)。

4. 确认使用支持Emoji的字体

右键PowerShell窗口标题栏→选择「属性」→切换到「字体」选项卡,选择Segoe UI Emoji或Noto Color Emoji这类支持emoji的字体,应用设置后重启窗口。


内容的提问来源于stack exchange,提问作者Meghan M.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 22:03:14