Skip to content

Commit

Permalink
module: fix ERR_REQUIRE_ESM for parentPath null
Browse files Browse the repository at this point in the history
PR-URL: #40145
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
guybedford committed Sep 28, 2021
1 parent d9ebc04 commit 481c160
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1459,8 +1459,8 @@ E('ERR_REQUIRE_ESM',
return msg;
}
const path = require('path');
const basename = path.basename(filename) === path.basename(parentPath) ?
filename : path.basename(filename);
const basename = parentPath && path.basename(filename) ===
path.basename(parentPath) ? filename : path.basename(filename);
if (hasEsmSyntax) {
msg += `\nInstead change the require of ${basename} in ${parentPath} to` +
' a dynamic import() which is available in all CommonJS modules.';
Expand Down

0 comments on commit 481c160

Please sign in to comment.