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

升级Expo SDK 48后Webpack模块解析失败求助

Expo SDK 48 Webpack 解析失败问题解决方案

针对报错 Module not found: Can't resolve './dist/abort-controller',这是Webpack 5的严格模块解析规则导致的——它要求导入必须使用完整文件扩展名,而相关依赖的导入路径缺少扩展名。以下是具体解决步骤:

  • 修改Webpack配置,添加扩展名解析
    在项目的webpack.config.js中,确保resolve.extensions包含.mjs及其他必要扩展名:

    module.exports = {
      resolve: {
        extensions: ['.mjs', '.js', '.jsx', '.json', '.ts', '.tsx'],
      },
    };
    
  • 适配Expo自带Webpack配置
    若使用Expo官方的@expo/webpack-config,在自定义配置中扩展默认规则:

    const createExpoWebpackConfigAsync = require('@expo/webpack-config');
    
    module.exports = async function (env, argv) {
      const config = await createExpoWebpackConfigAsync(env, argv);
      config.resolve.extensions.push('.mjs');
      return config;
    };
    
  • 清理缓存与重装依赖
    执行以下命令清除旧依赖和缓存,重新构建:

    rm -rf node_modules
    rm package-lock.json yarn.lock
    npm install
    npx expo start --clear
    
  • 更新abort-controller依赖
    确保依赖版本兼容SDK 48,执行升级命令:

    npm install abort-controller@latest
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 10:27:42