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

执行npm start报错:TypeError: runner.metro.getBundler(...).getWatcher不是函数

解决Expo项目npm start时的Watcher相关错误

问题重现

执行npm start时出现以下错误:

验证警告

Validation Warning:

  Unknown option "watcher" with value {"additionalExts": ["env.development.local", "env.local", "env.development", "env"]} was found.
  This is probably a typing mistake. Fixing it will remove this message.

类型错误

Starting Metro Bundler
TypeError: runner.metro.getBundler(...).getBundler(...).getWatcher is not a function
TypeError: runner.metro.getBundler(...).getBundler(...).getWatcher is not a function
    at Object.observeFileChanges (C:\Users\USER\Desktop\Numify\node_modules\@expo\cli\build\src\start\server\metro\waitForMetroToObserveTypeScriptFile.js:44:60)
    at MetroBundlerDevServer.watchEnvironmentVariables (C:\Users\USER\Desktop\Numify\node_modules\@expo\cli\build\src\start\server\metro\MetroBundlerDevServer.js:209:51)
    at DevServerManager.watchEnvironmentVariables (C:\Users\USER\Desktop\Numify\node_modules\@expo\cli\build\src\start\server\DevServerManager.js:193:35)
    at startAsync (C:\Users\USER\Desktop\Numify\node_modules\@expo\cli\build\src\start\startAsync.js:127:32)

已尝试卸载重装Metro模块,问题未解决。


解决方案

1. 移除或修复Metro配置中的无效watcher选项

  • 打开项目根目录的metro.config.js(或metro.config.json),查找包含watcher的配置段。
  • 新版Metro已废弃watcher配置项,直接删除该字段即可。若需要监听额外文件扩展名,可将additionalExts的值合并到resolver.sourceExts中,示例:
    module.exports = {
      resolver: {
        sourceExts: [...require('metro-config').default.getDefaultValues().resolver.sourceExts, 'env', 'env.local', 'env.development', 'env.development.local']
      }
    };
    

2. 同步Expo CLI与Metro版本

  • 版本不兼容是核心诱因之一,执行以下命令更新到匹配的最新版本:
    npm install @expo/cli@latest metro@latest --save-dev
    
  • 若更新后仍有问题,清理依赖缓存并重新安装:
    rm -rf node_modules package-lock.json
    npm install
    

3. 检查项目配置文件

  • 确认app.json或app.config.js中无错误的文件监听相关配置,避免触发Metro的异常调用逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 03:41:14