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

React Email执行yarn email命令出现ERR_REQUIRE_ESM错误求助

解决react-email执行yarn email dev --port 3001时的ERR_REQUIRE_ESM错误

问题描述

按照react-email官方文档操作时,执行命令yarn email dev --port 3001遇到以下错误:

***\node_modules\ora\index.js:65
                if (process.platform === 'win32') {
                           ^

Error [ERR_REQUIRE_ESM]: require() of ES Module ***\node_modules\strip-ansi\index.js from ***\node_modules\ora\index.js not supported.
Instead change the require of ***\node_modules\strip-ansi\index.js in ***\node_modules\ora\index.js to a dynamic import() which is available in all CommonJS modules.
    at mod.require (***\node_modules\next\dist\server\require-hook.js:65:28)
    at Object.<anonymous> (***\Cutify\node_modules\ora\index.js:7:19)
    at mod.require (***\node_modules\next\dist\server\require-hook.js:65:28)
    at Object.<anonymous> (***\node_modules\react-email\cli\index.js:420:26) {
  code: 'ERR_REQUIRE_ESM'
}

已查阅官方文档及相关问题未找到可行方案,寻求解决办法。

解决方案

  • 锁定ora兼容版本:错误根源是ora依赖的strip-ansi为ESM模块,但当前ora版本用CommonJS的require导入导致不兼容。在项目的package.json中添加resolutions字段锁定ora到兼容版本:

    "resolutions": {
      "ora": "^5.4.1"
    }
    

    执行yarn install重新安装依赖后,再运行yarn email dev --port 3001。

  • 切换包管理器尝试:不同包管理器对ESM/CommonJS的处理逻辑有差异。删除node_modules和yarn.lock,改用npm install或pnpm install安装依赖后,重新执行启动命令。

  • 检查项目模块类型配置:确认项目根目录package.json中是否设置了"type": "module",如果有,暂时移除该配置(react-email CLI目前更适配CommonJS环境),再尝试启动服务。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 16:12:10