Error: only absolute urls are supported #481
Comments
I am getting the same error when trying to run tests (using Enzyme and Ava):
|
The server don't have an origin so the default domain name is unknown. Therefore relative url won't work. Hence the error. Supporting file:// protocol is also out of the question. I would like to close this issue as relative to |
Agreed with @jimmywarting. You may want to use |
maybe use |
@kopax I was having the same issue, it seems to be some issues with the types files. I fixed my issue which was that I was using it like: fetch({url, headers: {Authorization: `token ${process.GIT_TOKEN}`}}) instead of fetch(url, {headers: {Authorization: `token ${process.GIT_TOKEN}`}}) |
How would you fix this in nextjs when using getStaticPaths() and getStaticProps() ? |
that's for next.js only |
It looks like there's something wrong with the URL in the fetch method. |
@Monster880 How did you change the url it to make it work? I am having the same problem. |
const baseURL = 'http://localhost'
fetch(new URL(url, baseURL)) |
Thanks @jimmywarting - could you advise what I might be missing? function updateDisplayName() {
const baseURL = 'http://localhost'; // 'http://localhost:8000';
const url = process.env.AUTHO_POST_ENDPOINT;
fetch(new URL(url, baseURL, {
method: 'POST',
headers: {authorization: 'Bearer ' + process.env.AUTHO_TOKEN},
data: '{"user_metadata": {"displayName": "FooName"}',
}))
.then(function(response) {
console.log('update', response.data);
}).catch(function(error) {
console.error(error);
});
}; |
there is nothing in the spec that defines same with request body: it should be fetch(new URL(url, baseURL, {
method: 'POST',
headers: {authorization: 'Bearer ' + process.env.AUTHO_TOKEN},
- data: '{"user_metadata": {"displayName": "FooName"}',
+ body: '{"user_metadata": {"displayName": "FooName"}',
})) |
@jimmywarting Thank you! I am now getting a response! |
Would be nice if the error message saying |
This is necessary because node-fetch does not support relative urls: node-fetch/node-fetch#481 More on node-fetch: - Use node-fetch for Node.js tests, since Node.js does not implement fetch API. Injecting the implementation was not possible since fetch seems to require the owner object to implement the Window interface. On further study it might be possible.
This happens when you are trying to get a relative path is
../../my/path/to/myfile.json
. This is supported in browsers (tested on Firefox, Chrome and Safari).My issue is in testing, tests fail because of the above error, which is annoying because now I have a distinction between the browser and the node environment running the tests.
This is the stack trace beyond my code:
I have added a comment in
isomorphic-fetch
discussion: matthew-andrews/isomorphic-fetch#76 (comment), but would like to attract attention on this use case here too.The text was updated successfully, but these errors were encountered: