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

Windows环境Next.js 13.4集成Sentry遇Webpack URI处理错误求助

解决Next.js + Sentry在Windows下的UnhandledSchemeError

这个错误是因为Windows盘符路径(比如C:devtestsentry.server.config.ts)被Webpack误识别成了自定义URI scheme(c:),而非本地文件路径,导致Webpack无法处理。以下是几个可行的解决办法:

1. 显式指定Sentry配置文件路径

在next.config.js中调用withSentryConfig时,传入第二个配置对象,明确指定配置文件的相对路径,避免插件自动解析路径出错:

const { withSentryConfig } = require("@sentry/nextjs");

/** @type {import('next').NextConfig} */
const nextConfig = {};

module.exports = withSentryConfig(nextConfig, {
  configFile: "./sentry.server.config.ts",
  clientConfigFile: "./sentry.client.config.ts",
  edgeConfigFile: "./sentry.edge.config.ts",
});

2. 升级@Sentry/nextjs到最新版本

旧版本的Sentry Next.js插件在Windows路径处理上可能存在兼容性bug,执行命令更新:

npm install @sentry/nextjs@latest

3. 确认配置文件位置

确保sentry.client.config.ts、sentry.server.config.ts、sentry.edge.config.ts三个文件放在项目根目录,与next.config.js、package.json同级,不要放在子文件夹内。

4. 手动修复Webpack路径解析(兜底方案)

如果前三种方法无效,可以在Next.js的Webpack配置中添加规则,将c:开头的路径转换为file:协议:

const { withSentryConfig } = require("@sentry/nextjs");

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config) => {
    config.resolve.plugins = config.resolve.plugins || [];
    config.resolve.plugins.push({
      apply(resolver) {
        resolver.hooks.resolve.tap('WindowsPathFix', (request) => {
          if (request.request && request.request.startsWith('C:')) {
            request.request = `file:///${request.request.replace(/\\/g, '/')}`;
          }
        });
      },
    });
    return config;
  },
};

module.exports = withSentryConfig(nextConfig);

优先尝试前三个方法,第四个作为备选方案。通常显式指定配置文件路径即可解决问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 23:58:16