fix: safe FormData detection for WeChat Mini Program (#7306)#7324
Merged
jasonsaayman merged 2 commits intoaxios:v1.xfrom Feb 14, 2026
Merged
fix: safe FormData detection for WeChat Mini Program (#7306)#7324jasonsaayman merged 2 commits intoaxios:v1.xfrom
jasonsaayman merged 2 commits intoaxios:v1.xfrom
Conversation
Contributor
Author
|
Hi maintainers 👋, this PR fixes issue #7306 by safely detecting FormData in WeChat Mini Programs. |
Member
Contributor
|
@jasonsaayman I have started the AI code review. It will take a few minutes to complete. |
jasonsaayman
approved these changes
Feb 14, 2026
Contributor
Author
|
Thank you for reviewing and merging this PR. Happy to see this fix helping Axios users in WeChat Mini Programs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
Axios throws "TypeError: Cannot read property 'FormData' of undefined" in WeChat Mini Program environments because it directly accesses self/window.FormData. These globals are not available in that environment, causing a crash on import.
Fix:
Introduce safe global detection (globalThis → self → window → global) and guard FormData usage via FormDataCtor. This ensures Axios does not crash when FormData is absent, while preserving existing behavior in browsers and Node.js.
Tests:
All unit and browser tests pass locally. The change is a pure JS guard and does not alter behavior in environments where FormData exists.
Code change: