Skip to content

Fetch only takes a string, not a UrlWithLegacySupport #74

Closed
@roderik

Description

@roderik

In https://github.com/ipfs/js-ipfs-utils/blob/master/src/http.js#L134-L159 the call to make is put into iso-url which returns a UrlWithLegacySupport.

A few lines lower, this is passed into fetch.

This throws the following error:

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received an instance of URLWithLegacySupport
    at validateString (internal/validators.js:124:11)
    at Url.parse (url.js:159:3)
    at urlParse (url.js:154:13)
    at new Request (/home/coder/project/node_modules/node-fetch/lib/request.js:27:16)
    at /home/coder/project/node_modules/node-fetch/index.js:51:17
    at new Promise (<anonymous>)
    at new Fetch (/home/coder/project/node_modules/node-fetch/index.js:49:9)
    at Fetch (/home/coder/project/node_modules/node-fetch/index.js:37:10)
    at Client.fetch (/home/coder/project/node_modules/ipfs-utils/src/http.js:148:36)
    at Client.fetch (/home/coder/project/node_modules/ipfs-http-client/src/lib/core.js:162:20)
    at Client.post (/home/coder/project/node_modules/ipfs-utils/src/http.js:190:17)
    at addAll (/home/coder/project/node_modules/ipfs-http-client/src/add-all.js:22:27)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at last (/home/coder/project/node_modules/it-last/index.js:15:20)
    at Object.add (/home/coder/project/node_modules/ipfs-http-client/src/add.js:18:14)

Changing the fetch call to the following fixes this, but I'm wondering how this code has been in use in this repo for a long time and suddenly it starts erroring out for me.

    const response = await timeout(fetch(url.href, {

I tried Node 12 and 14, no difference there. (I was hoping url.parse was changed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugA bug in existing code (including security flaws)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions