From d74532dd4c75c18bfb5a31d57b278f4638382693 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 9 May 2019 16:47:56 -0400 Subject: [PATCH] module: simplify createRequire() validation --- lib/internal/modules/cjs/loader.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index d02c632bcee5a7..f7056c448505c3 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -852,10 +852,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 {