diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 43cffd89cb819d..332767b3ab225b 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -858,10 +858,9 @@ const createRequireError = 'must be a file URL object, file URL string, or' +
 
 function createRequire(filename) {
   let filepath;
-  if (typeof filename === 'object' && !(filename instanceof URL)) {
-    throw new ERR_INVALID_ARG_VALUE('filename', filename, createRequireError);
-  } else if (typeof filename === 'object' ||
-    typeof filename === 'string' && !path.isAbsolute(filename)) {
+
+  if (filename instanceof URL ||
+      (typeof filename === 'string' && !path.isAbsolute(filename))) {
     try {
       filepath = fileURLToPath(filename);
     } catch {