From 323ca3215cc62bcdce78c70f0c1869c2faec85ac Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 19 Oct 2023 08:27:43 -1000 Subject: [PATCH] feat(compartment-mapper): improve unresolved module error message --- .../src/parse-cjs-shared-export-wrapper.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/compartment-mapper/src/parse-cjs-shared-export-wrapper.js b/packages/compartment-mapper/src/parse-cjs-shared-export-wrapper.js index 54cd200540..479f7c07eb 100644 --- a/packages/compartment-mapper/src/parse-cjs-shared-export-wrapper.js +++ b/packages/compartment-mapper/src/parse-cjs-shared-export-wrapper.js @@ -132,6 +132,11 @@ export const wrap = ({ }); const require = (/** @type {string} */ importSpecifier) => { + if (!has(resolvedImports, importSpecifier)) { + throw new Error( + `Cannot find module "${importSpecifier}" in "${location}"`, + ); + } const namespace = compartment.importNow(resolvedImports[importSpecifier]); // If you read this file carefully, you'll see it's not possible for a cjs module to not have the default anymore. // It's currently possible to require modules that were not created by this file though.