-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
URLSearchParams
polyfill breaks fetch
#674
Comments
How do you include |
I'm working on a project created by @vue/cli. To my understanding, this project use babel with @vue/cli-plugin-babel/preset, which just require @vue/babel-preset-app, which should use @babel/preset-env with Use this works: const res = await fetch('/api/xxx', {
method: 'POST',
body: (new URLSearchParams({ a: 'b' })).toString(),
header: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
}) But as in https://developer.mozilla.org/en-US/docs/Web/API/Request/Request, body should work directly with URLSearchParams URLSearchParams itself works fine, it just does not work with fetch. |
Ok, I see the problem. Seems required one more wrapper for |
I can't understand, why do spec writers love to over complicate simple things... KISS |
@huww98 could you check it with the version from the |
OK, I resolved this by delete the symbolic link created by npm and copy /path/to/core-js/packages/core-js to my node_modules. Then remove cache and rebuild. I can confirm the version from master branch fixes my problem. thanks. |
Sorry, but how is this supposed to work with |
@vkurko it will not work with the current version of |
@zloirock thanks for your answer. But the issue is not related to |
@vkurko sorry, I mixed up the contexts. Here the same situation, just change We can't make |
@zloirock Unfortunately wrapping fetch(url, {
method: 'POST',
body: String(new URLSearchParams({ a: 'b' }))
}) So if the only way of sending a correct request is to set headers explicitly then the wrapper that is added by Thanks |
I upgraded to @vue/cli@4, which use core-js@3. And my
fetch
breaks on WeChat (based on chrome 66, as shown in UA).I'm using it like this:
Before upgrade, this will add header 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8', and use 'a=b' as body. Now it just send a blank body and does not add header.
I think it is because the
URLSearchParams
polyfill.fetch
can no longer recognize the polyfill as anURLSearchParams
. Manually adding header and converting body to string do work, however, is it possible to fix this? I think this can be hard, since we don't know how Chrome determine whether an object is an URLSearchParamsThe text was updated successfully, but these errors were encountered: