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
TypeError invalid URL when using relative URL and searchParams #236
Comments
Duplicate of #228 |
Unfortunately, due to limitations in the WHATWG URL API, We try to limit the impact of this problem by only using See #228 (comment) for more details and thoughts on how we could fix this. I am happy to review any PR related to this problem, however there probably won't be an elegant solution without help from the folks at WHATWG. I would encourage anyone who runs into this to open an issue over on https://github.com/whatwg/url/issues. We basically need utilities for parsing and manipulating relative URLs. They can be faked in userland, but they should be standardized. Until there is a proper fix within Ky, my suggestion to you is to do something like this: const baseUrl = isRunningOnServer ? `https://${host}` : '';
const response = await $http.$get('list', {
prefixUrl: `${baseUrl}/api`,
searchParams: {
page: 1,
}
}); For the |
@sholladay oh! thank you for your solution! |
Not only on sever. Got same problem in |
@Airkro I don't have an iOS device on hand to test with. Could you provide a video or other evidence of this to help debug it? I'll test with BriwserStack when I get a moment. |
I don't have an iOS device either. I borrow that for a moment from my workmate. I used Then: ky.get('sample', {
- prefixUrl: '/api/'
+ prefixUrl: window.location.origin + '/api/'
}) But it is unnecessary on |
Interesting, good to know. Unfortunately, I'm not sure we'll be able to do anything about it if it's a bug with the environment. We used to resolve the request URL against the document's base URL, which is how I would fix it, but that caused problems in some environments. I think your workaround is good. However, I recommend using |
I just opened PR #271 to fix this. It won't magically make things work if the |
hello!
when using ky with
@nuxt/http
but encountered an error.the code above triggers an error:
and then i check
node_modules/ky/umd.js
and MDN URL()The text was updated successfully, but these errors were encountered: