Skip to content

If the runtime environment does not have/support FormData and Blob. How should I do? #5543

Closed

Description

@lcysgsg

Describe the issue

I am developing a axios-adapter-uniapp for uniapp, when I apply it in wechat miniprogram, I got ReferenceError: FormData is not defined.

It seems to be used in inside axios, and I couldn't Eliminate this influence.

The axios-adapter-uniapp work with axios^0, couldn't work with axios^1.

Can you give me some guidance? Thank you very much.

屏幕截图 2023-02-13 175309

Example Code

here is the adapter [https://github.com/lcysgsg/axios-adapter-uniapp/tree/v1](https://github.com/lcysgsg/axios-adapter-uniapp/tree/v1)

Expected behavior

Avoid being affected by FormData and Blob.

Axios Version

1.3.2

Adapter Version

custom

Browser

wechat miniprogram

Browser Version

wechat miniprogram

Node.js Version

wechat miniprogram

OS

wechat miniprogram

Additional Library Versions

No response

Additional context/Screenshots

No response

Activity

  1. lcysgsg commented on Feb 14, 2023

    @lcysgsg
    ContributorAuthor

    Actually, there are two other places with the same problem:

    1. The lib\platform\browser\index.js -> classes.Blob got the same issue. I am going to send a PR as a reference example.
    2. lib\env\classes\FormData.js import a form-data lib, it also has problems with FormData is unavailable. And I thought of two options to resolve:
      1. Ask form-data to help fix the issue, and ask axios to update the dependent version.
      2. axios make sure import form-data only when environment is Node in lib\env\classes\FormData.js.

    It was tested on my local. This allows the combined adapter to run across platforms, not only Node and Browsers.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions