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

Sentry Sourcemaps上传报错:bad json类型不符,求排查方案

问题:Sentry上传Sourcemaps时报JSON格式错误

负责为前端应用集成Sentry,构建后用以下命令上传sourcemaps到Sentry流水线:

sentry-cli releases -o "myorg" -p "myproject" files "$VERSION" upload-sourcemaps ./

执行后接近成功,但出现报错:

DEBUG   2022-12-09 15:18:39.496486472 +00:00 sentry-cli version: 2.10.0, platform: "linux", architecture: "x86_64"
INFO    2022-12-09 15:18:39.496862713 +00:00 sentry-cli was invoked with the following command line: "sentry-cli" "releases" "-o" "uswitchcom" "-p" "my-mojo-ui" "files" "1.0.1638" "upload-sourcemaps" "./"
> Found 69899 release files
> Analyzing 69899 sources
> Rewriting sources
error: bad json: invalid type: map, expected a string at line 1 column 328

项目用Parcel构建,dist文件夹结构扁平:

dist
├── index.0bf95743.js
├── index.0bf95743.js.map
├── index.a11de8bb.js
├── index.a11de8bb.js.map
├── index.fee677fd.css
├── index.fee677fd.css.map
├── index.html

(不清楚为何有两个index文件,但应用运行正常)
浏览器调试工具中sourcemap可正常工作,请问问题出在哪里?

解决方案

1. 缩小上传范围,排除无关文件

当前命令上传./下所有文件,导致扫描了69899个文件,大概率是某个非sourcemap/JSON的文件被sentry-cli误解析。直接指定dist目录上传:

sentry-cli releases -o "myorg" -p "myproject" files "$VERSION" upload-sourcemaps ./dist

2. 检查sourcemap的sources字段格式

报错提示JSON解析时期望字符串却得到了map,说明某个sourcemap文件的"sources"数组存在格式错误——Parcel偶尔会生成非字符串类型的sources项(比如把路径写成对象而非字符串)。

  • 手动打开几个.map文件,检查"sources"数组里的每一项是否都是字符串格式。
  • 如果发现异常,重新构建项目,或升级Parcel到稳定版本修复该问题。

3. 精确排除非必要文件

即使指定了dist目录,也可以通过--exclude参数过滤html、css等无需解析的文件,减少扫描量:

sentry-cli releases -o "myorg" -p "myproject" files "$VERSION" upload-sourcemaps ./dist --exclude "*.html" --exclude "*.css"

4. 升级sentry-cli版本

你当前使用的2.10.0版本可能存在JSON解析的bug,升级到最新版本尝试:

npm install -g @sentry/cli

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 12:40:25