Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lcysgsg opened this issue Feb 13, 2023 · 1 comment · Fixed by #5545
Closed

Comments

@lcysgsg
Copy link
Contributor

lcysgsg commented Feb 13, 2023

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

@lcysgsg
Copy link
Contributor Author

lcysgsg commented Feb 14, 2023

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
Labels
None yet
Projects
None yet
1 participant