Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aliabudal opened this issue Jun 19, 2024 · 1 comment
Open

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

aliabudal opened this issue Jun 19, 2024 · 1 comment

Comments

@aliabudal
Copy link
Contributor

aliabudal commented Jun 19, 2024

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]'
@justinwaite
Copy link

Solution for me was to remove installGlobals from my remix app. I believe with newer versions of node, the polyfills are no longer necessary. Note that if you use remix-serve then it will run installGlobals automatically, so use an express server or similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants