Messages containing @ character are silently dropped in production build with JIT compilation
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- typescript
調査の方向性
vite-plugin-vue-i18n の JIT コンパイルエントリーポイントから始め、提供されている Vue 3、vue-i18n、Vite の例を使って問題を再現します。@ を含む静的なロケール文字列がどのように解析されるかを追跡し、本番ビルドでリテラルメッセージが保持され、空の文字列を黙って返すのではなく無効な構文が報告されることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Reporting a bug?
Bug Description
When using vue-i18n with Vite in production mode, messages containing the @ character are silently removed (return empty string) during the build process. This only occurs in production builds (vite build), while development mode (vite dev) works correctly.
The issue appears to be in the JIT compilation phase where static string analysis misidentifies @ as ICU MessageFormat syntax, causing the entire message to be discarded without warning.
Steps:
- Create a Vue 3 + vue-i18n (v9) + Vite project
- Add a locale message containing
@:
// src/locales/zh-CN.ts
export default {
ddns: {
placeholder: {
domainRr: '如: www (为空则使用@)',
ipAddress: '请输入IP地址'
}
}
}
- Use in component:
<template>
<n-input :placeholder="t('ddns.placeholder.domainRr')" />
<n-input :placeholder="t('ddns.placeholder.ipAddress')" />
</template>
<script setup>
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
</script>
- Development (
npm run dev): Both placeholders display correctly - Production (
npm run build+npm run preview):domainRrinput has empty placeholder (returns empty string)ipAddressinput displays correctly
Expected Behavior
The @ character should be treated as literal text in production builds, consistent with development behavior. The message should display: 如: www (为空则使用@)
Actual Behavior
- Development:
t('ddns.placeholder.domainRr')returns'如: www (为空则使用@)'✅ - Production:
t('ddns.placeholder.domainRr')returns''(empty string) ❌ - No build errors or warnings are emitted
Environment
{
"vue": "^3.5.24",
"vue-i18n": "^9.14.4",
"vite": "^7.2.4",
"@vitejs/plugin-vue": "^6.0.1",
"naive-ui": "^2.43.2",
"typescript": "~5.9.3"
}
- Build Tool: Vite 7.2.4
- Vue I18n Version: 9.14.4
- Node Version: [e.g., 20.x]
- OS: [e.g., Windows/macOS/Linux]
Root Cause Analysis
After extensive debugging, the issue appears to be in the JIT compilation phase:
- Static Analysis Phase: The JIT compiler statically analyzes message strings during build time to pre-compile them.
- ICU Syntax Misidentification: The
@character is used in ICU MessageFormat for argument selection (plural rules, etc.). The parser likely encounters@and treats it as ICU syntax, fails to parse it correctly (since it's just literal text), and silently discards the entire message. - Why Function Works: Arrow functions
() => 'text@text'cannot be statically analyzed (not executed at build time), so they bypass the check:// ❌ Static string - analyzed and removed domainRr: '如: www (为空则使用@)' // ✅ Arrow function - preserved for runtime domainRr: () => '如: www (为空则使用@)'
Workarounds (Verified)
Workaround 1: Arrow Function (Recommended)
export default {
ddns: {
placeholder: {
domainRr: () => '如: www (为空则使用@)' // Bypasses static analysis
}
}
}
Then in component:
const result = t('ddns.placeholder.domainRr')
const text = typeof result === 'function' ? result() : result
Workaround 2: Array Join
domainRr: ['如: www (为空则使用', '@', ')'].join('')
Workaround 3: Disable JIT (Last Resort)
// vite.config.ts
import vueI18n from '@intlify/vite-plugin-vue-i18n'
export default {
plugins: [
vueI18n({
jitCompilation: false // Falls back to runtime compilation
})
]
}
Suggested Fix
The JIT compiler should:
- Distinguish ICU syntax from literal text:
@should only be treated as special syntax when it's part of a valid ICU structure (e.g.,{count, plural, one {# item} other {# items}}), not when it's just a character in a sentence. - Fail loudly: If the parser encounters what it thinks is invalid ICU syntax, it should emit a warning/error during build rather than silently dropping the message.
Related git changes: https://github.com/ProgramCX/FoxNAS-Web/commit/f76943efb2ec075aae407a02bb8e6da69113c007
Expected behavior
The @ character should be treated as literal text in production builds, consistent with development behavior. The message should display: 如: www (为空则使用@)
Reproduction
not fixed: https://github.com/ProgramCX/FoxNAS-Web/tree/e4964780959cc37041292f9e08e683771921d206
fixed: https://github.com/ProgramCX/FoxNAS-Web/tree/f76943efb2ec075aae407a02bb8e6da69113c007
Issue Package
vite-plugin-vue-i18n
System Info
System:
OS: Windows 11 10.0.26200
CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
Memory: 1.20 GB / 15.72 GB
Binaries:
Node: 20.19.0 - D:\Program Files\nodejs\node.EXE
Yarn: 1.22.22 - C:\Users\Progr\AppData\Roaming\npm\yarn.CMD
npm: 10.8.2 - D:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 144.0.7559.133
Edge: Chromium (131.0.2903.146)
Internet Explorer: 11.0.26100.7296
npmPackages:
vite: ^7.2.4 => 7.3.1
vue: ^3.5.24 => 3.5.27
vue-i18n: ^9.14.4 => 9.14.4
Screenshot
Additional context
- Unicode escape fails: Using
\u0040instead of@also gets removed, suggesting the parser resolves escapes before ICU analysis. - Hardcoded strings work:
<n-input placeholder="如: www (为空则使用@)" />displays correctly, confirming it's not a UI framework issue (Naive UI handles@fine). - Silent failure: The most critical aspect is that this fails silently - no build error, no runtime warning, just empty strings in production.
Validations
- Read the Contributing Guidelines.
- Read the README
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- 主要言語
- TypeScript
- スター
- 269
- フォーク
- 46
- 平均マージ
- 3時間 54分
- マージ済み PR(30日)
- 57
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
intlify/bundle-tools のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
intlify/bundle-tools#600 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
intlify/bundle-tools#517 · コメント 4 件 · リアクション 4 件 ·
メンテナーはふだん 1 日以内に返信
-
Minimize keysオープン
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
intlify/bundle-tools#502 ·
メンテナーはふだん 1 日以内に返信
-
status: proposal
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
intlify/bundle-tools#416 ·
メンテナーはふだん 1 日以内に返信
-
status: review needed
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
intlify/bundle-tools#399 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
intlify/bundle-tools の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
CopilotKit/openmuse#215 ·
メンテナーはふだん 3 日以内に返信
-
b:minor bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
software-mansion/argent#1698 ·
メンテナーはふだん 1 日以内に返信
-
e2e-failure ready-to-code
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
redhat-developer/rhdh-plugin-export-overlays#4624 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信