module: fix ERR_REQUIRE_ESM for parentPath null

PR-URL: https://github.com/nodejs/node/pull/40145
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Guy Bedford 2021-09-18 11:57:52 -07:00
parent d9ebc04e9b
commit 481c1609d8
1 changed files with 2 additions and 2 deletions

View File

@ -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.';