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

使用Bun+Express运行Remix时source-map-support报Column=-1错误

解决Bun+Express+Remix项目中source-map-support的Column=-1错误

我在使用Bun搭配Express运行Remix项目时,触发了source-map-support的报错:TypeError: Column must be greater than or equal to 0, got -1。尝试自定义retrieveSourceMap配置恢复源映射,甚至省略该选项,错误依然存在,且已确认对应的.map文件存在。

我的配置信息

  • source-map-support自定义配置:
sourceMapSupport.install({
  retrieveSourceMap: function (source) {
    console.log(source, `${source}.map`)
    return {
      url: source,
      map: fs.readFileSync(`${source}.map`, "utf8"),
    }
  },
})
  • remix.config.js:
/** @type {import('@remix-run/dev').AppConfig} */
export default {
  ignoredRouteFiles: ["**/.*"],
  serverModuleFormat: "esm",
  appDirectory: "src/remix",
};
  • Remix引入方式:
import * as build from "../build/index.js"

app.all("*", createRequestHandler({ build: build as any }))
  • 开发命令:
"remix dev --manual -c \"bun --watch run src/index.ts\""

完整报错日志

/Users/dangoodman/code/sellmyai/build/index.js
583 |     if (aNeedle[aLineName] <= 0) {
584 |       throw new TypeError('Line must be greater than or equal to 1, got '
585 |                           + aNeedle[aLineName]);
586 |     }
587 |     if (aNeedle[aColumnName] < 0) {
588 |       throw new TypeError('Column must be greater than or equal to 0, got '
                  ^
TypeError: Column must be greater than or equal to 0, got -1
      at SourceMapConsumer_findMapping (/Users/dangoodman/code/sellmyai/node_modules/source-map-support/node_modules/source-map/lib/source-map-consumer.js:588:13)
      at SourceMapConsumer_originalPositionFor (/Users/dangoodman/code/sellmyai/node_modules/source-map-support/node_modules/source-map/lib/source-map-consumer.js:653:17)
      at mapSourcePosition (/Users/dangoodman/code/sellmyai/node_modules/source-map-support/source-map-support.js:244:28)
      at wrapCallSite (/Users/dangoodman/code/sellmyai/node_modules/source-map-support/source-map-support.js:397:20)
      at prepareStackTrace (/Users/dangoodman/code/sellmyai/node_modules/source-map-support/source-map-support.js:446:39)
      at new RowsNotFound (/Users/dangoodman/code/sellmyai/build/index.js:550:30)
      at /Users/dangoodman/code/sellmyai/build/index.js:2503:11
      at processTicksAndRejections (:61:77)

/Users/dangoodman/code/sellmyai/node_modules/source-map-support/source-map-support.js
/Users/dangoodman/code/sellmyai/node_modules/source-map-support/node_modules/source-map/lib/source-map-consumer.js
586 |     }
587 |     if (aNeedle[aColumnName] < 0) {
588 |       throw new TypeError('Column must be greater than or equal to 0, got '
589 |                           + aNeedle[aColumnName]);
590 |     }
591 |
                                                                          ^
TypeError: Column must be greater than or equal to 0, got -1
      at SourceMapConsumer_findMapping (/Users/dangoodman/code/sellmyai/node_modules/source-map-support/node_modules/source-map/lib/source-map-consumer.js:591:69)
      at SourceMapConsumer_originalPositionFor (/Users/dangoodman/code/sellmyai/node_modules/source-map-support/node_modules/source-map/lib/source-map-consumer.js:662:10)
      at mapSourcePosition (/Users/dangoodman/code/sellmyai/node_modules/source-map-support/source-map-support.js:28:1)
      at wrapCallSite (/Users/dangoodman/code/sellmyai/node_modules/source-map-support/source-map-support.js:398:7)
      at prepareStackTrace (/Users/dangoodman/code/sellmyai/node_modules/source-map-support/source-map-support.js:449:55)
      at captureStackTrace (native:1:1)
      at new RowsNotFound (/Users/dangoodman/code/sellmyai/src/remix/routes/dashboard.settings.tsx:302:13)

解决方法

1. 升级source-map-support到最新版本

旧版本的source-map-support在处理Bun生成的源映射时可能存在兼容性问题,执行以下命令升级:

bun add source-map-support@latest

2. 修改source-map-support的安装配置,过滤无效列值

在安装source-map-support时,通过wrapCallSite钩子手动修正负数列值,避免触发报错:

import sourceMapSupport from 'source-map-support';
import fs from 'fs';

sourceMapSupport.install({
  retrieveSourceMap: function (source) {
    const mapPath = `${source}.map`;
    if (fs.existsSync(mapPath)) {
      return {
        url: source,
        map: fs.readFileSync(mapPath, "utf8"),
      };
    }
    return null;
  },
  wrapCallSite: (callSite) => {
    // 修正列值为负数的情况,强制设为0
    const column = callSite.getColumnNumber();
    if (column < 0) {
      // 重写getColumnNumber方法返回合法值
      return Object.create(callSite, {
        getColumnNumber: {
          value: () => 0,
        },
      });
    }
    return callSite;
  },
});

3. 调整Remix的源映射生成配置

在remix.config.js中明确指定源映射类型,确保生成的.map文件格式正确:

/** @type {import('@remix-run/dev').AppConfig} */
export default {
  ignoredRouteFiles: ["**/.*"],
  serverModuleFormat: "esm",
  appDirectory: "src/remix",
  // 添加源映射配置
  sourcemap: true,
  serverSourcemap: true,
};

4. 临时禁用source-map-support(仅调试用)

如果上述方法都无效,可以临时禁用source-map-support,先保证项目运行,后续再排查:

// 注释掉sourceMapSupport.install()相关代码
// sourceMapSupport.install(...);

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 08:25:30