ethanent / phin

Node HTTP client
MIT License
576 stars 33 forks source link

TypeError: URL is not a constructor #50

Closed maxall41 closed 3 years ago

maxall41 commented 4 years ago

I'm trying to make a simple post request but i'm getting the error TypeError: URL is not a constructor at new CentraRequest (CentraRequest.js?0a95:14) at module.exports (createRequest.js?ca09:4) at phin (phin.min.js?e014:1) at _callee$ (VM1328 index.vue:333) at tryCatch (runtime.js?96cf:45) at Generator.invoke [as _invoke] (runtime.js?96cf:274) at Generator.prototype.<computed> [as next] (runtime.js?96cf:97) at asyncGeneratorStep (asyncToGenerator.js?1da1:3) at _next (asyncToGenerator.js?1da1:25) at eval (asyncToGenerator.js?1da1:32) Here's my code: await p({ url: "example.com", method: "POST", data: { test: 'hello' } }); Does anybody know how to fix this?

ethanent commented 4 years ago

The issue is probably that your URL is not correctly formatted! Be sure to append an “https:” or “http:” scheme to the start of the address.

maxall41 commented 4 years ago

i changed 'example.com' to 'http://example.com' but i'm still getting the same error

ethanent commented 4 years ago

Hmm, ok. Which Node version are you using?

maxall41 commented 4 years ago

i'm using v12.16.2

MarcelloTheArcane commented 4 years ago

I have the same issue. My URL is formatted correctly too.

NPM version 6.14.5

Does https://stackoverflow.com/questions/44738065/uncaught-typeerror-url-is-not-a-constructor-using-whatwg-url-object-support-for help?

cbetta commented 4 years ago

Running into the same issues here. I am using phin 3.5.0, node 14.5.0 and npm 6.14.5 in a React project (react 16.13.1).

cbetta commented 4 years ago

I just realized that phin is not meant for frontend usage, which explains the URL error.

jdforsythe commented 3 years ago

@maxall41 it looks like you're trying to use this with Vue. It is a Node package that uses native Node modules. You could try using Browserify but you may run into this issue https://github.com/ethanent/centra/issues/6