fix: Handle UTF-8 BOM in config loading and build script
- main.js: Strip UTF-8 BOM when reading config.json - build-client.bat: Write config.json without BOM using [System.Text.UTF8Encoding]::new($false) PowerShell's -Encoding UTF8 writes BOM by default, which can cause JSON parsing issues in Node.js. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -43,7 +43,12 @@ function loadConfig() {
|
|||||||
console.log(`Checking: ${configPath} - exists: ${exists}`);
|
console.log(`Checking: ${configPath} - exists: ${exists}`);
|
||||||
try {
|
try {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
const configData = fs.readFileSync(configPath, "utf-8");
|
// Use utf-8 and strip BOM if present (Windows Notepad adds BOM)
|
||||||
|
let configData = fs.readFileSync(configPath, "utf-8");
|
||||||
|
// Remove UTF-8 BOM if present
|
||||||
|
if (configData.charCodeAt(0) === 0xFEFF) {
|
||||||
|
configData = configData.slice(1);
|
||||||
|
}
|
||||||
appConfig = JSON.parse(configData);
|
appConfig = JSON.parse(configData);
|
||||||
console.log("Config loaded from:", configPath);
|
console.log("Config loaded from:", configPath);
|
||||||
console.log("Config content:", JSON.stringify(appConfig, null, 2));
|
console.log("Config content:", JSON.stringify(appConfig, null, 2));
|
||||||
|
|||||||
@@ -313,8 +313,8 @@ if not exist "%CONFIG_FILE%" (
|
|||||||
goto :eof
|
goto :eof
|
||||||
)
|
)
|
||||||
|
|
||||||
REM 使用 PowerShell 更新 backend.embedded = true
|
REM 使用 PowerShell 更新 backend.embedded = true (使用 UTF8 without BOM)
|
||||||
powershell -Command "$config = Get-Content '%CONFIG_FILE%' -Raw | ConvertFrom-Json; if (-not $config.backend) { $config | Add-Member -NotePropertyName 'backend' -NotePropertyValue @{} }; $config.backend.embedded = $true; $config | ConvertTo-Json -Depth 10 | Set-Content '%CONFIG_FILE%' -Encoding UTF8"
|
powershell -Command "$config = Get-Content '%CONFIG_FILE%' -Raw | ConvertFrom-Json; if (-not $config.backend) { $config | Add-Member -NotePropertyName 'backend' -NotePropertyValue @{} }; $config.backend.embedded = $true; $json = $config | ConvertTo-Json -Depth 10; [System.IO.File]::WriteAllText('%CONFIG_FILE%', $json, [System.Text.UTF8Encoding]::new($false))"
|
||||||
|
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo %RED%[ERROR]%NC% 更新 config.json embedded 設定失敗
|
echo %RED%[ERROR]%NC% 更新 config.json embedded 設定失敗
|
||||||
|
|||||||
Reference in New Issue
Block a user