Skip to content
New issue

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

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

Already on GitHub? # to your account

url.parse('/404') throws, unlike in Node.js #290

Closed
mhart opened this issue Aug 1, 2024 · 0 comments · Fixed by #299
Closed

url.parse('/404') throws, unlike in Node.js #290

mhart opened this issue Aug 1, 2024 · 0 comments · Fixed by #299
Labels
bug Something isn't working

Comments

@mhart
Copy link

mhart commented Aug 1, 2024

Environment

Cloudflare Workers: wrangler 3.64.0 w/ experimental:nodejs_compat_v2

Reproduction

require('url').parse('/404')

Describe the bug

You get TypeError: Failed to construct 'URL': Invalid URL (or similar) due to unenv's use of new URL() to parse.

In Node.js, with url.parse('/404') you get:

Url {
  protocol: null,
  slashes: null,
  auth: null,
  host: null,
  port: null,
  hostname: null,
  hash: null,
  search: null,
  query: null,
  pathname: '/404',
  path: '/404',
  href: '/404'
}

Additional context

This occurs in Next.js as it passes around "urls" like /404 and /500 internally a lot.

The code comments note divergence is potentially an issue – and indeed this is a case where it is.

The compat matrix over at https://workers-nodejs-compat-matrix.pages.dev/ should probably be changed to be a "Mismatch" instead of a "Supported" for url.parse due to this (and no doubt other strings exhibit divergence too)

Logs

No response

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant