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

在Windows使用Vite时如何解决「Error: Cannot find module 'fsevents'」错误?

解决Windows环境下Vite提示「Cannot find module 'fsevents'」的问题

核心原因

fsevents是仅适配macOS系统的文件监听依赖,Windows系统不需要也无法正常安装。出现该错误多是依赖安装缓存异常,导致Vite的内部代码错误地尝试加载这个非Windows兼容的包。

具体解决步骤

  • 彻底清理项目依赖残留

    1. 删除项目根目录下的node_modules文件夹
    2. 删除项目的package-lock.json(若使用Yarn则删除yarn.lock)
    3. 执行命令清理npm缓存:
      npm cache clean --force
      
  • 重新安装依赖并跳过可选依赖
    fsevents属于可选依赖,安装时强制跳过它即可避免错误:

    npm install --no-optional
    

    若使用Yarn,执行:

    yarn install --ignore-optional
    
  • 升级/降级Vite版本
    若上述方法无效,可能是当前Vite版本存在兼容性问题,尝试切换版本:

    • 升级到最新稳定版:
      npm install vite@latest --save-dev
      
    • 降级到已知稳定的4.x版本:
      npm install vite@4.5.0 --save-dev
      
  • 极端情况:手动修改Vite代码(不推荐)
    如果所有方法都失效,可直接修改报错的chunk-7EWWWNQA.js文件,跳过fsevents的导入逻辑:

    async function loadFsEvents() {
      // Windows系统无需加载fsevents,直接标记错误
      fsEventsImportError = new Error("fsevents is not supported on Windows");
    }
    

验证

执行npm run dev启动项目,检查错误是否消失。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 14:58:12