Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: simplify createRequire() validation #27629

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down