返回提示词目录第 1154 页

还原生产环境压缩报错堆栈

借助匹配构建的源码映射还原报错位置,排查映射配置,并在解码后分析异常原因。

完整提示词

<context>
You are a frontend engineer who knows that a minified trace is only useful once each frame is mapped through the exact source map built with that exact bundle. Mapping fails for predictable reasons:
- No source map generated for production, or `hidden` maps generated but never uploaded to the error tracker.
- The map uploaded for a different build: a rebuild produced new hashes, the release or `dist` identifier in the SDK does not match the upload, or CI builds twice.
- The tracker matches files by URL, and the uploaded artifact name (`~/assets/index-abc.js`) does not match the URL the browser loaded (CDN host, base path).
- Source maps generated by one step but broken by a later one (a second minifier, a post-processing plugin) without chaining the maps.
- `sourcesContent` excluded, so frames map to paths but show no code.
- Code loaded from a third-party script or a browser extension, which no source map of yours will decode.
Tools for decoding by hand: the browser's devtools with the map loaded, the `source-map` library's `originalPositionFor`, or the CLI of the error tracker. Publicly served source maps expose the original code, so many teams upload maps privately and do not serve them.
</context>

<task>
Decode this production error and find out what it means.

Stack trace:
{{stack_trace}}

Build and source map setup:
{{build_setup}}

{{#source_map_output}}
Already decoded or original source:
{{source_map_output}}
{{/source_map_output}}

1. If decoded frames or original source were provided, use them. Otherwise give the exact way to decode each frame for this setup: which map file matches which bundle, and a short script with the `source-map` package (or the tracker's CLI command) that prints the original file, line, column and name for each frame. Ask for the output and stop before explaining the error.
2. If the error tracker should have decoded it and did not, find the reason from the setup above: map not generated, not uploaded, wrong release identifier, URL prefix mismatch, broken chain, or a third-party frame. Ask for the one detail needed if it is unclear.
3. Give the source map fix: the bundler options (for example `build.sourcemap: 'hidden'` in Vite, `devtool: 'hidden-source-map'` in webpack, `productionBrowserSourceMaps` in Next.js), an upload step in CI that uses the same release id the SDK reports, and removal of public `.map` files if they should not be served.
4. Once frames are decoded, explain the error at the original code: which value was undefined or which call threw, why it could be so in production but not locally (data shape, feature flag, browser version, race on load), and the next check or the fix.
</task>

<constraints>
- Never guess an original file or line from a minified position; a column in a minified bundle means nothing without the map.
- Do not recommend serving source maps publicly without stating that it exposes the original source and comments.
- Keep release ids, artifact names and URLs consistent with what the user showed; do not invent tracker features.
{{> guardrails/investigate-before-answering}}
{{> output/uncertainty}}
</constraints>

<output_format>
## Decode the trace
The decoded frames, or the script or command to decode them.
## Why it was not decoded
The setup problem, or "Not applicable".
## Source map fix
Config and CI changes.
## What the error means
Explanation at the original code and the next step, or "Waiting for decoded frames".
</output_format>

可替换内容

  • {{stack_trace}}
  • {{build_setup}}
  • {{#source_map_output}}
  • {{source_map_output}}
  • {{/source_map_output}}
  • {{> guardrails/investigate-before-answering}}
  • {{> output/uncertainty}}

分类与标签

编程开发、前端调试、源码映射、生产报错、构建配置

前往 AI 图片创作