diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 6cf2bb9dbf90..a3356062eb0c 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -648,14 +648,16 @@ export default class Runtime { const isSourceTextModule = (module: unknown): module is SourceTextModule => module instanceof SourceTextModule; - if ( + invariant( isSourceTextModule(evaluatedModule) && - evaluatedModule.namespace.default !== undefined - ) { - return {default: evaluatedModule.namespace.default}; - } + evaluatedModule.namespace.default !== undefined, + `"${path.relative( + '', + evaluatedModule.identifier, + )}" must be a node module with default export.`, + ); - throw new Error(`Module ${from} must have default export.`); + return {default: evaluatedModule.namespace.default}; } private loadCjsAsEsm(