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

Node.js React项目package.json构建脚本执行失败(JSON语法错误)

Fixing "Unexpected token } in JSON at position X" in package.json

Hey there, let's get this build error sorted out—this is almost always a JSON syntax mistake in your package.json file, which both Yarn and npm can't parse correctly. Here's how to fix it step by step:

1. Locate and fix the JSON syntax error

The error points directly to position 175 in your package.json, so start by opening the file and checking that area. Common culprits include:

  • A trailing comma after the last key-value pair in an object (JSON doesn't allow these!)
  • Mismatched curly braces ({/}) or quotes (make sure all strings are wrapped in straight double quotes)
  • A missing comma between key-value pairs

To make this easier:

  • Use a code editor like VS Code, which will highlight JSON syntax errors in red automatically.
  • Run this command in your project folder to get a detailed breakdown of the error:
    node -e "require('./package.json')"
    
    Node.js will try to load your package.json and spit out a precise error message about what's wrong.

For example, if you have something like this (note the trailing comma after "build"):

"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts build",
}

You'll need to remove that extra comma to fix the syntax.

2. Verify the fix

Once you've corrected the syntax, test it first with npm (since you mentioned it gives more detailed errors):

npm run build

If this works, the JSON issue is resolved. You can then try running yarn build again—it should now succeed too.

3. Clean package manager caches (if needed)

If you still see errors after fixing the JSON, the cache might be holding onto a corrupted version of your package.json:

  • For Yarn:
    yarn cache clean
    
  • For npm:
    npm cache clean --force
    

After cleaning, re-run the build command.

4. Check for hidden issues (rare)

If all else fails, make sure your package.json is saved in UTF-8 encoding (no weird special characters or full-width punctuation marks) and that there are no invisible whitespace characters messing up the parsing.

内容的提问来源于stack exchange,提问作者Nompumelelo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 09:04:59