From bd6bb899763c17c341da16403d220d7cef69f17c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Sun, 24 Jun 2018 02:09:49 +0300 Subject: [PATCH] errors: fix ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK This restores a broken and erroneously removed error, which was accidentially renamed to ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK (notice the "INTST" vs "INST") in 921fb84687fb8135075c1f001383e9b0b863f4b5 (PR #16874) and then had documentation and implementation removed under the old name in 6e1c25c45672b70f4b6c6c8af56d9c0762bfae04 (PR #18857), as it appeared unused. This error code never worked or was documented under the mistyped name ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK, so renaming it back to ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK is a semver-patch fix. Refs: https://github.com/nodejs/node/issues/21440 Refs: https://github.com/nodejs/node/pull/21470 Refs: https://github.com/nodejs/node/pull/16874 Refs: https://github.com/nodejs/node/pull/18857 --- doc/api/errors.md | 8 ++++++++ lib/internal/errors.js | 3 +++ lib/internal/modules/esm/loader.js | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index c0773caf7c9bbc..222bbd810c90e6 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1312,6 +1312,14 @@ strict compliance with the API specification (which in some cases may accept `func(undefined)` and `func()` are treated identically, and the [`ERR_INVALID_ARG_TYPE`][] error code may be used instead. + +### ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK + +> Stability: 1 - Experimental + +An [ES6 module][] loader hook specified `format: 'dynamic` but did not provide a +`dynamicInstantiate` hook. + ### ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 51bf07adf3d91b..14f4c3eb72a6d1 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -725,6 +725,9 @@ E('ERR_MISSING_ARGS', } return `${msg} must be specified`; }, TypeError); +E('ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK', + 'The ES Module loader may not return a format of \'dynamic\' when no ' + + 'dynamicInstantiate function was provided'); E('ERR_MISSING_MODULE', 'Cannot find module %s', Error); E('ERR_MODULE_RESOLUTION_LEGACY', '%s not found by import in %s.' + diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index b3023fcd4f8e36..41de3f48740dcb 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -93,7 +93,7 @@ class Loader { let loaderInstance; if (format === 'dynamic') { if (typeof this._dynamicInstantiate !== 'function') - throw new ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK(); + throw new ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK(); loaderInstance = async (url) => { debug(`Translating dynamic ${url}`);