From 7bdc69426772a2915bc348f491aa7eaa44d422df 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 PR-URL: https://github.com/nodejs/node/pull/21493 Reviewed-By: Gus Caplan Reviewed-By: Trivikram Kamat Reviewed-By: Vse Mozhet Byt Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Ron Korving Reviewed-By: Luigi Pinca --- doc/api/errors.md | 8 ++++++++ lib/internal/errors.js | 3 +++ lib/internal/modules/esm/loader.js | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 57f64367c1d3eb..19f9f9abaec60f 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1330,6 +1330,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 be37c96d018704..4d2dd7f69410e2 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -739,6 +739,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', Error); 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 2fa10c7eab9b44..89f40939e7a4f3 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -5,7 +5,7 @@ const { ERR_INVALID_RETURN_PROPERTY, ERR_INVALID_RETURN_PROPERTY_VALUE, ERR_INVALID_RETURN_VALUE, - ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK, + ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK, ERR_UNKNOWN_MODULE_FORMAT } = require('internal/errors').codes; const { URL } = require('url'); @@ -118,7 +118,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}`);