在 Jest 中使用 Axios 运行单元测试时,我遇到与
follow-redirects
相关的持续警告:
Warning: exclude follow-redirects from browser builds
重现步骤:
我正在使用 Axios 在 Node.js 项目中发出 HTTP 请求。
运行涉及 Axios 的 Jest 测试(例如 axios.get())时,我始终在控制台输出中看到此警告。
测试本身正在通过,但每次都会出现警告。
我尝试过的:
我已确保 Jest 配置为使用 testEnvironment: 'node'。
我尝试模拟 Axios 和 follow-redirects 模块来避免这个问题。
我检查了 Jest 设置,以确保不会触发特定于浏览器的构建,但警告在所有测试文件中仍然存在。
运行 npm ls follow-redirects 显示 Axios 是使用此包的唯一直接依赖项。
我的环境:
Axios版本:1.7.7
笑话版本:29.7.0
我在 Nx monorepo 上运行 Vitest 时遇到了类似的问题。我注意到我的 pnpm 锁定文件中的 axios 依赖解析如下所示:
- [email protected]
- follow-redirects: 1.15.8([email protected])
然后查看跟随重定向
1.15.8
和 1.15.9
之间的差异,似乎负责错误日志记录的 nope.js
文件已被删除,取而代之的是更优雅的浏览器排除处理:
我尝试安装
1.15.9
,最新版本中不再出现错误日志记录。
因此,也许可以考虑以下几点:
pnpm update follow-redirects
1.15.9
,在我的情况下,这将是 pnpm add follow-redirects@^1.15.9