node-fetch: Gives error "Only absolute URLs are supported" even though the URL is absolute
I did
require('node-fetch')('http://localhost:3000/')
and it gave me an error: TypeError: Only absolute URLs are supported
Reproduction
Steps to reproduce the behavior:
- Get node version 15.2.1
- run
npm install node-fetch@2.6.1 - run
node -p "require('node-fetch')('http://localhost:3000/')"
Expected behavior
I expected it to run fine without any errors and return the response. https://www.npmjs.com/package/node-fetch#fetchurl-options
Your Environment
| software | version |
|---|---|
| node-fetch | 2.6.1 |
| node | 15.2.1 |
| npm | 6.14.8 |
| Operating System | Windows 10 v2004 build 19041.630 |
Additional context
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 17
- Comments: 16 (5 by maintainers)
I have had a similar issue, and the problem was multiple versions of node-fetch. In my case I was running in a monorepo and the test app and the support packages resolved to different node_modules folder. Somewhere deep in the implementation there is a check against a JS symbol which would not match in this case.
@pavelloz @steelx could you submit the exact code that aren’t working, along with exact versions of node-fetch, node, npm, and os?
Is this not working?
I have the same issue (for a long time, i just didnt write about it) when trying to build project with routify which depends on node-fetch. Whats weird, it works when i start i dev mode (and thats how i work around the issue… i just dont build, i leave project in dev mode forever).
It looks like a lot of people are waiting for it to be resolved: https://github.com/mailgun/mailgun-js/issues/118
node-fetch: 2.6.1 node: v16.11.0 npm: 8.0.0 macos: 10.15.7
@tbrannam yes you are right. I got fixed my problem by using FormData and Axios in combination