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

Expo React Native应用--web模式运行时出现abort-controller错误求助

解决Expo Web模式下abort-controller模块解析错误

我运行命令 npx expo start --web 启动Expo Web应用时,控制台抛出以下错误:

ERROR in ./node_modules/abort-controller/polyfill.mjs:2
Module not found: Can't resolve './dist/abort-controller'
Did you mean 'abort-controller.mjs'?
BREAKING CHANGE: The request './dist/abort-controller' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '.mjs' file, or a '.js' file where the package.json contains "type": "module").
The extension in the request is mandatory for it to be fully specified.

以下是可行的解决方法:

  • 更新abort-controller包到最新版本
    这个问题大多是旧版本abort-controller的ESM模块路径解析bug,直接执行命令更新:

    npm update abort-controller
    # 用yarn的话执行:
    yarn upgrade abort-controller
    

    更新完成后重新运行npx expo start --web,基本能解决问题。

  • 添加Webpack解析配置(更新包无效时用)
    如果更新后还是报错,需要修改Expo的Webpack配置,让它自动补充模块扩展名:

    1. 先安装依赖(没装过的话):
      npm install --save-dev @expo/webpack-config
      
    2. 在项目根目录创建webpack.config.js,写入以下内容:
      const createExpoWebpackConfigAsync = require('@expo/webpack-config');
      
      module.exports = async function (env, argv) {
        const config = await createExpoWebpackConfigAsync(env, argv);
        // 补充可解析的扩展名
        config.resolve.extensions.push('.mjs', '.js', '.jsx', '.json');
        // 针对abort-controller的路径别名(可选,仍报错时添加)
        config.resolve.alias['./dist/abort-controller'] = './dist/abort-controller.mjs';
        return config;
      };
      
    3. 重新启动Web服务:npx expo start --web
  • 清除缓存重试
    缓存异常也可能导致模块解析失败,执行命令清除缓存后重启:

    npx expo start --web --clear
    # 或者清除npm全局缓存:
    npm cache clean --force
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 19:02:19