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

使用WebPack的Serverless项目集成Sentry后无源代码上下文问题

Serverless Webpack项目集成Sentry后无法预览源代码

我在基于WebPack的Serverless项目中集成了Sentry,目前能在Sentry控制台看到错误信息,但没法像Python项目那样直接预览源代码。想请教下是否可以把源代码嵌入到Sentry中?我查了Sentry官方文档,没找到解决办法。

错误截图:
错误截图

已做的配置调整

我刚在tsconfig.json里加了inlineSources: true,完整配置如下:

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "lib": ["es2023", "dom"],
    "module": "commonjs",
    "skipLibCheck": true,
    "sourceMap": true,
    "inlineSources": true,
    "strict": true,
    "target": "es2023",
    "paths": {
      "~/*": ["./app/*"]
    }
  }
}

我已经生成了对应的sourcemap文件,WebPack的配置如下:

/* global __dirname */
/* global module */
/* global require */
/* eslint-disable @typescript-eslint/no-require-imports */
const path = require("path");
const slsw = require("serverless-webpack");

const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const nodeExternals = require("webpack-node-externals");
const CopyPlugin = require("copy-webpack-plugin");
const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");

/** @type { import('webpack').Configuration } */
module.exports = {
  mode: slsw.lib.webpack.isLocal ? "development" : "production",
  entry: slsw.lib.entries,
  // devtool: slsw.lib.webpack.isLocal ? 'source-map' : 'cheap-source-map',
  devtool: "source-map",
  target: "node",
  resolve: {
    extensions: [".ts"], // we just need TypeScript
    plugins: [new TsconfigPathsPlugin()],
  },
  output: {
    libraryTarget: "commonjs2",
    path: path.join(__dirname, ".webpack"),
    filename: "[name].js",
  },
  externals: ["aws-sdk", nodeExternals()],
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: "ts-loader",
        exclude: [
          /node_modules/,
          path.resolve(__dirname, ".webpack"),
          path.resolve(__dirname, ".serverless"),
        ],
        options: {
          transpileOnly: true,
          experimentalFileCaching: true,
        },
      },
    ],
  },
  plugins: [
    new ForkTsCheckerWebpackPlugin(),
    new CopyPlugin({ patterns: [{ from: "google.json", to: "google.json" }] }),
    sentryWebpackPlugin({
      org: "zoomies",
      project: "serverless",
      authToken: process.env.SENTRY_AUTH_TOKEN,
      telemetry: false,
    }),
  ],
};

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 14:19:52