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

Windows环境执行npm build遇UnhandledSchemeError问题求助

Webpack构建报错:UnhandledSchemeError(Windows环境)

错误信息

ERROR in C:Userschinnap1mdc-scorecardappsmfesrcindex.tsx
Module build failed: UnhandledSchemeError: Reading from "C:Userschinnap1mdc-testappsmfesrcindex.tsx" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "c:" URIs.
at C:\Users\chinnap1\mdc-scorecard\node_modules\webpack\lib\NormalModule.js:1013:10
at Hook.eval [as callAsync] (eval at create (C:\Users\chinnap1\mdc-scorecard\node_modules\tapable\lib\HookCodeFactory.js:33:10), :6:1)

问题原因

Windows环境下,Webpack将C:开头的路径识别成了URI scheme(类似http:、data:),而非本地文件路径,而Webpack默认仅支持data:和file:两种scheme,因此抛出未处理错误。

解决方法

  • 规范webpack配置中的路径写法
    避免直接硬编码Windows绝对路径,使用Node.js的path.resolve()方法生成正确的绝对路径,确保Webpack识别为本地文件。示例:

    const path = require('path');
    
    module.exports = {
      entry: path.resolve(__dirname, 'apps/mfe/src/index.tsx'),
      // 其他配置项...
    };
    
  • 替换代码中的硬编码绝对路径
    检查项目中所有导入语句,将C:\Users\chinnap1\...这类绝对路径替换为相对路径(如./index.tsx、../components/xxx.tsx),让Webpack按模块解析规则处理。

  • 配置资源文件处理规则
    如果是图片、字体等资源文件使用了绝对路径导入,可配置Webpack 5内置的asset/resource替代第三方loader:

    module.exports = {
      module: {
        rules: [
          {
            test: /\.(png|jpe?g|gif|svg|woff2?)$/,
            type: 'asset/resource',
          },
        ],
      },
    };
    
  • 升级Webpack版本
    旧版Webpack在Windows路径解析上存在兼容性问题,升级到最新稳定版(如Webpack 5.x)可修复部分路径识别bug。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 17:06:08