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

Chrome未将SourceMap映射应用到控制台输出问题求助

问题:Electron 18开发环境下控制台错误无法映射到源码

我用Webpack搭建项目,开发环境生成带内联SourceMap(包含源码)的bundle,作为Electron 18.0.4(对应Chrome 98.0.4758.109)的插件运行。Chrome的Sources面板能正常显示源码,用source-map包测试映射也正确,但控制台输出的错误只指向打包后文件的万余行位置,没法映射回原源码。

相关配置文件

tsconfig.json

{
  "compilerOptions": {
    "types": ["node"],
    "target": "ES6",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "sourceMap": true,
    "inlineSources": true
  },
  "include": ["src", "declaration.d.ts"]
}

webpack.config.js

import { fileURLToPath, URL } from "url";
import pkg from "webpack";
const { DefinePlugin, EnvironmentPlugin } = pkg;

export default async function (env) {
  const mode = env.mode || "development";
  const prod = mode == "production";

  return {
    mode: prod ? "production" : "development",
    entry: "./src/main.ts",
    devtool: mode === "development" ? "inline-source-map" : "source-map",
    performance: {
      hints: false, // ignore size since the bundle is run locally
    },
    module: {
      rules: [
        {
          test: /\.ts$/,
          exclude: /node_modules/,
          use: {
            loader: "ts-loader",
          },
        }
      ],
    },
    ignoreWarnings: [/Failed to parse source map/],
    plugins: [
      new EnvironmentPlugin({
        SENTRY_DSN: "",
      }),
      new DefinePlugin({
        __SENTRY_DEBUG__: !prod,
      }),
    ],
    resolve: {
      extensions: [".ts", ".js"],
    },
    externals: {
      obsidian: "commonjs obsidian",
    },
    output: {
      path: fileURLToPath(new URL(".", import.meta.url)),
      filename: "main.js",
      libraryTarget: "commonjs",
    },
  };
}

相关截图

  • Sources面板:可正常加载并显示原源码文件
    Chrome开发者工具Sources标签页
  • 控制台错误:仅指向打包后main.js的具体行号,无源码映射
    开发者工具控制台中的错误

这会不会是Chrome的bug?这类问题按理说不该出现。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 16:15:26