From 80f30741bd1ecc485fbeb4162fae8bbd6ed7b9b5 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 18 May 2019 10:09:48 -0400 Subject: [PATCH] esm: use correct error arguments ERR_UNKNOWN_FILE_EXTENSION expects a single argument. This commit fixes the argument count. PR-URL: https://github.com/nodejs/node/pull/27763 Fixes: https://github.com/nodejs/node/issues/27761 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca Reviewed-By: Richard Lau --- lib/internal/modules/esm/default_resolve.js | 3 +-- test/es-module/test-esm-invalid-extension.js | 13 +++++++++++++ test/fixtures/es-modules/import-invalid-ext.mjs | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/es-module/test-esm-invalid-extension.js create mode 100644 test/fixtures/es-modules/import-invalid-ext.mjs diff --git a/lib/internal/modules/esm/default_resolve.js b/lib/internal/modules/esm/default_resolve.js index 67b8db716c5b01..88377689ce4fd7 100644 --- a/lib/internal/modules/esm/default_resolve.js +++ b/lib/internal/modules/esm/default_resolve.js @@ -91,8 +91,7 @@ function resolve(specifier, parentURL) { if (isMain) format = type === TYPE_MODULE ? 'module' : 'commonjs'; else - throw new ERR_UNKNOWN_FILE_EXTENSION(fileURLToPath(url), - fileURLToPath(parentURL)); + throw new ERR_UNKNOWN_FILE_EXTENSION(fileURLToPath(url)); } return { url: `${url}`, format }; } diff --git a/test/es-module/test-esm-invalid-extension.js b/test/es-module/test-esm-invalid-extension.js new file mode 100644 index 00000000000000..9e676e57d1b90f --- /dev/null +++ b/test/es-module/test-esm-invalid-extension.js @@ -0,0 +1,13 @@ +'use strict'; +require('../common'); +const fixtures = require('../common/fixtures'); +const assert = require('assert'); +const { spawnSync } = require('child_process'); +const fixture = fixtures.path('/es-modules/import-invalid-ext.mjs'); +const child = spawnSync(process.execPath, ['--experimental-modules', fixture]); +const errMsg = 'TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension'; + +assert.strictEqual(child.status, 1); +assert.strictEqual(child.signal, null); +assert.strictEqual(child.stdout.toString().trim(), ''); +assert(child.stderr.toString().includes(errMsg)); diff --git a/test/fixtures/es-modules/import-invalid-ext.mjs b/test/fixtures/es-modules/import-invalid-ext.mjs new file mode 100644 index 00000000000000..2de34252192a98 --- /dev/null +++ b/test/fixtures/es-modules/import-invalid-ext.mjs @@ -0,0 +1 @@ +import './simple.wat';