diff --git a/lib/internal/modules/esm/fetch_module.js b/lib/internal/modules/esm/fetch_module.js index 19ff8c4b946346..7638f94b3fe525 100644 --- a/lib/internal/modules/esm/fetch_module.js +++ b/lib/internal/modules/esm/fetch_module.js @@ -148,7 +148,9 @@ function fetchWithRedirects(parsed) { err.message = `Cannot find module '${parsed.href}', HTTP 404`; throw err; } - if (res.statusCode < 200 || res.statusCode >= 400) { + // This condition catches all unsupported status codes, including + // 3xx redirection codes without `Location` HTTP header. + if (res.statusCode < 200 || res.statusCode >= 300) { throw new ERR_NETWORK_IMPORT_DISALLOWED( res.headers.location, parsed.href,