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

迁移至Monorepo并切换Expo托管工作流后RN找不到AccessibilityInfo文件

问题

迁移至Monorepo并切换回Expo托管工作流后,React Native出现文件查找异常——仅搜索.native相关扩展名的文件,无法识别.ios/.android扩展名,报错信息如下:

None of these files exist:
  * ../../node_modules/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo(.native|.native.js|.js|.native.jsx|.jsx|.native.ts|.ts|.native.tsx|.tsx|.native.cjs|.cjs|.native.native|.native|.native.json|.json)
  * ../../node_modules/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo/index(.native|.native.js|.js|.native.jsx|.jsx|.native.ts|.ts|.native.tsx|.tsx|.native.cjs|.cjs|.native.native|.native|.native.json|.json)
  12 |
  13 | // Components
> 14 | import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';

当前使用Expo 44 / React Native 64.3版本,怀疑问题与Metro配置相关,现有配置如下:

const { getDefaultConfig } = require('expo/metro-config');
const path = require('path');

const projectRoot = __dirname;
const workspaceRoot = path.resolve(__dirname, '../..');

const config = getDefaultConfig(__dirname);

config.watchFolders = [workspaceRoot];
config.resolver = {
  ...config.resolver,
  nodeModulesPath: [
    path.resolve(projectRoot, 'node_modules'),
    path.resolve(workspaceRoot, 'node_modules'),
  ],
  sourceExts: ['js', 'jsx', 'ts', 'tsx', 'cjs'],
};

config.transformer = {
  getTransformOptions: async () => ({
    transform: {
      experimentalImportSupport: false,
      inlineRequires: true,
    },
  }),
  minifierPath: require.resolve('metro-minify-esbuild'),
  minifierConfig: {},
};

module.exports = config;

解决方法

  • 不要直接替换sourceExts,而是基于默认配置扩展。默认sourceExts包含平台相关扩展名的处理逻辑,直接覆盖会丢失.ios/.android的识别规则,修改resolver部分:
config.resolver = {
  ...config.resolver,
  nodeModulesPath: [
    path.resolve(projectRoot, 'node_modules'),
    path.resolve(workspaceRoot, 'node_modules'),
  ],
  // 保留默认扩展名,新增需要的cjs类型
  sourceExts: [...config.resolver.sourceExts, 'cjs'],
};
  • 检查resolver.platforms配置,确保包含ios和android,若默认缺失则手动添加:
config.resolver = {
  ...config.resolver,
  platforms: ['ios', 'android', 'native'],
  // 其他配置保持不变
};
  • 清除Metro缓存,执行npx expo start --clear,确保新配置生效。
  • 确认Monorepo结构下,react-native依赖在工作区根目录或项目目录正确安装,避免版本不一致导致的文件路径异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 02:05:32