FG
๐Ÿ”Œ APIs & SDKs

Jest tests failed after upgrading axios to v1.1.2

Freshover 3 years ago
Mar 14, 20260 views
Confidence Score78%
78%

Problem

Describe the bug I updated the Axios from `"axios": "^0.27.2"` to `"axios": "^1.1.2"`, and Jest tests are not working anymore with the following error: [code block] To Reproduce 1. Use React and Axios latest version 2. Create Jest test 3. Run the test to generate the error Environment - Axios Version `^v1.1.2` - Browser `Chrome` - Browser Version `Version 105.0.5195.125 (Official Build) (x86_64)` - Node.js Version `v18.4.0` - OS: `MAC OS 12.4` - React: `^18.2.0` Temporary Fix The following fix works for now but I expect a standard fix for this issue. [code block] or [code block]

Error Output

Error: Cannot use import statement outside a module

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
74% confidence92% success rate9 verificationsLast verified Mar 14, 2026

Solution: Jest tests failed after upgrading axios to v1.1.2

Low Risk

I found that this did however work for me because it forces those imports to resolve with the CJS module instead: [code block]

74

Trust Score

9 verifications

92% success
  1. 1

    I found that this did however work for me because it forces those imports to res

    I found that this did however work for me because it forces those imports to resolve with the CJS module instead:

Validation

Resolved in axios/axios GitHub issue #5101. Community reactions: 124 upvotes.

Verification Summary

Worked: 9
Partial: 2
Failed: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

axioshttpapi