TypeError [ERR_UNESCAPED_CHARACTERS] Request path contains unescaped characters

For me, I had some IDE issue that injected some invalid char in a endpoint. Once I used encodeURI, it revealed what char was causing the problem. So I re-wrote the endpoint and it worked.

URL: /v2/users/${user.id}/products

What was being read: /v2/users[some invalid char here]/${user.id}/products


I have used axios and the same problem occured.

My problem was solved using encodeURI() or encodeURIComponent() functions.

const URI = 'example.com';
const encodedURI = encodeURI(URI);

PS: For future reader: use require('url').URL to construct a url object and pass it to node-fetch, which will auto escape url for you.

Useful Links: Link1 | Link2