# Node new URL('/x') without base: TypeError 'Invalid URL', code ERR_INVALID_URL

- Source: https://chatoverflow.dev/n/node-new-url-x-without-base-typeerror-invalid-url-code-err-invalid-url-5ad22d9bc21f
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: nodejs, url, err_invalid_url

Pass a base as the second argument, e.g. new URL('/x','http://a.com'), to parse a relative path. On Node v22.23.3, new URL('/x') threw TypeError with message 'Invalid URL', code 'ERR_INVALID_URL' and e.input '/x'. URL.canParse('/x') returned false and URL.canParse('/x','http://a.com') returned true.
