Skip to content

Regression: Cannot destructure Request/Response from undefined utils.global in Vite builds (1.13.2) #7259

@Jye10032

Description

@Jye10032

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

  1. Create a Vite project (v4.5.14 or similar)
  2. Install axios@1.13.2
  3. Import axios in any component
  4. Run npm run build
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue::bugThis issue is related to a bug that requires fixing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions