Skip to content

TypeError: Invalid URL caused by mismatch in fetch() #10

@aliabudal

Description

@aliabudal

Describe the issue

Using Remix 2.9.2 with any version of libsql/client >= 0.6.0 results in the following error:

node:internal/url:814
    const href = bindingUrl.parse(input, base, raiseException);
                            ^

TypeError: Invalid URL
    at new URL (node:internal/url:814:29)
    at new Request (/home/ali/Desktop/remix-template-starter/node_modules/@remix-run/web-fetch/dist/lib.node.cjs:1437:16)
    at /home/ali/Desktop/remix-template-starter/node_modules/@remix-run/web-fetch/dist/lib.node.cjs:1732:19
    at new Promise (<anonymous>)
    at fetch (/home/ali/Desktop/remix-template-starter/node_modules/@remix-run/web-fetch/dist/lib.node.cjs:1729:9)
    at fetchWithAgentSelection (file:///home/ali/Desktop/remix-template-starter/node_modules/@libsql/isomorphic-fetch/node.js:19:12)
    at #flush (file:///home/ali/Desktop/remix-template-starter/node_modules/@libsql/hrana-client/lib-esm/http/stream.js:245:23)
    at #flushPipeline (file:///home/ali/Desktop/remix-template-starter/node_modules/@libsql/hrana-client/lib-esm/http/stream.js:233:20)
    at #flushQueue (file:///home/ali/Desktop/remix-template-starter/node_modules/@libsql/hrana-client/lib-esm/http/stream.js:223:32)
    at file:///home/ali/Desktop/remix-template-starter/node_modules/@libsql/hrana-client/lib-esm/http/stream.js:181:50 {
  code: 'ERR_INVALID_URL',
  input: '[object Request]'
}

Downgrading to libsql/client 0.5.6 fixes the issue, as discovered by the following issues:
tursodatabase/libsql-client-ts#204
prisma/prisma#23774

However, after investigating, I've noticed that the issue isn't due to using a version of libsql/client >= 0.6.0, as I was able to use 0.6.2 with the condition that I downgrade libsql/isomorphic-fetch to 0.1.12 which is a dependency of @libsql/hrana-client which is a dependency of libsql/client. I've then started looking at the changes between libsql/isomorphic-fetch 0.1.12 and 0.2.0, which is just this 1 commit thankfully: 218800b

And what I've noticed is that now, we are passing the entire Request object as the first argument to the fetch function, going back at the error mentioned above, specifically this one here:

at fetch (/home/ali/Desktop/remix-template-starter/node_modules/@remix-run/web-fetch/dist/lib.node.cjs:1729:9)

What is happening here is that the fetch function from @remix-run/web-fetch, tries to treat it as a string URL, leading to the ERR INVALID URL error, because we are trying to pass it the entire Request object:

 input: '[object Request]'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions