From f8a5f496a47c1b2f19b5ef4b6fae97120e312c4e Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 9 Sep 2020 08:24:18 -0700 Subject: [PATCH] errors: simplify ERR_REQUIRE_ESM message generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because of the condition that starts the `if` block, we know that `parentPath` must be truthy. So there is no need to check for that in the template string that generates the error message. PR-URL: https://github.com/nodejs/node/pull/35123 Reviewed-By: Anna Henningsen Reviewed-By: Juan José Arboleda Reviewed-By: Guy Bedford --- lib/internal/errors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 4c2330cc4ca225..2cf7df436b5e9f 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -1296,7 +1296,7 @@ E('ERR_REQUIRE_ESM', filename : path.basename(filename); msg += '\nrequire() of ES modules is not supported.\nrequire() of ' + - `${filename} ${parentPath ? `from ${parentPath} ` : ''}` + + `${filename} from ${parentPath} ` + 'is an ES module file as it is a .js file whose nearest parent ' + 'package.json contains "type": "module" which defines all .js ' + 'files in that package scope as ES modules.\nInstead rename ' +