Describe the bug
Similar to #7153 which was fixed in #7155, there's another unsafe destructuring
in the fetch adapter that causes build failures.
While #7155 fixed the config.env destructuring, the utils.global destructuring
on line 15-17 still throws errors in certain build environments (Vite, webpack, etc).
Current code (lib/adapters/fetch.js:15-17):
const globalFetchAPI = (({Request, Response}) => ({
Request, Response
}))(utils.global);
Error:
TypeError: Cannot destructure property 'Request' of 'undefined' as it is undefined
at fetch.js:15:27
at fetch.js:17:1
This happens when utils.global is undefined or not fully initialized during
module loading in Vite and other build tools.
To Reproduce
- Create a Vite project (v4.5.14 or similar)
- Install axios@1.13.2
- Import axios in any component
- Run
npm run build
- Deploy and access in browser
Example deployment where this fails:
https://jye10032.github.io/NewsSystemPro/
(Before the workaround of downgrading to 1.7.7)
Expected behavior
The fetch adapter should handle cases where utils.global might be
temporarily unavailable during module initialization, similar to how
#7155 fixed the config.env issue.
Environment
- axios version: 1.13.2
- Build tool: Vite 4.5.14
- Browser: Chrome, Firefox (all modern browsers)
- Node.js: 20.x
- OS: macOS / Linux / Windows
Also reported by: Users in #7153 comments mentioning build issues
Additional context
This is blocking users from upgrading to the latest axios version in Vite projects.
I'm willing to submit a PR to fix this issue if the maintainers confirm it.
Describe the bug
Similar to #7153 which was fixed in #7155, there's another unsafe destructuring
in the fetch adapter that causes build failures.
While #7155 fixed the
config.envdestructuring, theutils.globaldestructuringon line 15-17 still throws errors in certain build environments (Vite, webpack, etc).
Current code (lib/adapters/fetch.js:15-17):
Error:
This happens when
utils.globalis undefined or not fully initialized duringmodule loading in Vite and other build tools.
To Reproduce
npm run buildExample deployment where this fails:
https://jye10032.github.io/NewsSystemPro/
(Before the workaround of downgrading to 1.7.7)
Expected behavior
The fetch adapter should handle cases where
utils.globalmight betemporarily unavailable during module initialization, similar to how
#7155 fixed the
config.envissue.Environment
Also reported by: Users in #7153 comments mentioning build issues
Additional context
This is blocking users from upgrading to the latest axios version in Vite projects.
I'm willing to submit a PR to fix this issue if the maintainers confirm it.