Unexpected 令牌
快速摘要
parser encountered symbol or keyword 哪里 它 做 不 belong — 通常 missing bracket, comma, or semicolon.
为什么发生
Missing comma 之间 项 in 数组 or 对象
Missing 关闭 bracket, brace, or parenthesis
Extra or misplaced punctuation
最小示例
✗ 错误代码
const arr = [1, 2 3]; // Missing comma after 2
console.log(arr);✓ 修复代码
const arr = [1, 2, 3]; // Comma added
console.log(arr); parser sees 2 3 and 做 不 know 什么 到 做 使用 3 — 它 expected comma or 关闭 bracket. 添加 comma fixes 它.
如何诊断
读取 错误 消息 — 它 names unexpected 令牌 and 它的 位置
检查 行 mentioned and 行 之前 它
Use bracket matching in 你的 editor 到 查找 unmatched pairs
如何修复
添加 missing comma, bracket, or semicolon
移除 extra punctuation
运行 formatter/linter 到 catch 语法 issues automatically
如何预防
Use code editor 使用 语法 highlighting and bracket matching
运行 linter 那个 catches 语法 错误 as 你 类型