Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
resolveUrl
✓ import { resolveUrl } from 'url-resolve-modern'
✗ import resolveUrl from 'url-resolve-modern'
Named export, not default. ESM-only, no CJS.
resolveUrlFrom
✓ import { resolveUrlFrom } from 'url-resolve-modern'
✗ const { resolveUrlFrom } = require('url-resolve-modern')
Named export. No CommonJS require() support.
isAbsoluteUrl
✓ import { isAbsoluteUrl } from 'url-resolve-modern'
✗ import { isAbsoluteUrl } from 'resolve-url'
Not part of resolve-url. Named export from this package.
UrlResolveError
✓ import { UrlResolveError } from 'url-resolve-modern'
✗ import { UrlResolveError } from 'url-resolve'
Custom error class. Only for this package.
Demonstrates basic resolveUrl, resolveUrlFrom, isAbsoluteUrl, and UrlResolveError usage.
import { resolveUrl, resolveUrlFrom, isAbsoluteUrl, UrlResolveError } from 'url-resolve-modern';
// Basic resolution
const result = resolveUrl('https://example.com/a/b/c', 'd');
console.log(result); // 'https://example.com/a/b/d'
// With explicit base
const result2 = resolveUrlFrom('https://example.com/static/js/app.js', '../css/style.css');
console.log(result2); // 'https://example.com/static/css/style.css'
// Check absolute URL
console.log(isAbsoluteUrl('https://example.com')); // true
console.log(isAbsoluteUrl('relative/path')); // false
// Error handling
try {
resolveUrl('relative/path');
} catch (e) {
if (e instanceof UrlResolveError) {
console.log('Missing base URL');
}
}
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module not supported
Package is ESM-only; using require() throws error.
fixSwitch to import statement or use dynamic import().
UrlResolveError: Cannot resolve relative URL without a base.
First argument to resolveUrl is relative and not in browser context.
fixProvide an absolute URL as first argument or use resolveUrlFrom with a base.
TypeError: URL constructor: https://example.com/a is not a valid URL.
Passed an invalid string that cannot be parsed as URL.
fixEnsure all URL strings are valid (e.g., encode spaces).
Module not found: Can't resolve 'url-resolve-modern' in ...
Package not installed or typo in import path.
fixRun npm install url-resolve-modern and verify import path.
Audit
Dependencies
No dependency data recorded yet.