Skip to content

fix: safe FormData detection for WeChat Mini Program (#7306) - #7324

Merged
jasonsaayman merged 2 commits into
axios:v1.xfrom
Shiwaangee:fix/wechat-formdata
Feb 14, 2026
Merged

jasonsaayman merged 2 commits into
axios:v1.xfrom
Shiwaangee:fix/wechat-formdata

Conversation

@Shiwaangee

Copy link
Copy Markdown
Contributor

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:

- typeof FormData === 'function' && thing instanceof FormData
+ FormDataCtor && thing instanceof FormDataCtor
Closes #7306.

@Shiwaangee

Copy link
Copy Markdown
Contributor Author

Hi maintainers 👋, this PR fixes issue #7306 by safely detecting FormData in WeChat Mini Programs.
All tests pass locally, and the change is scoped to a safe guard without affecting existing environments.
Looking forward to your review!

@jasonsaayman

Copy link
Copy Markdown
Member

@cubic-dev-ai

@cubic-dev-ai

cubic-dev-ai Bot commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai

@jasonsaayman I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@jasonsaayman
jasonsaayman merged commit 672491d into axios:v1.x Feb 14, 2026
6 checks passed
@Shiwaangee

Copy link
Copy Markdown
Contributor Author

Thank you for reviewing and merging this PR. Happy to see this fix helping Axios users in WeChat Mini Programs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants