Skip to content

Commit 417650e

Browse files
authored
chore: add invariant on ESM support in dynamic import (#11164)
1 parent 26b2237 commit 417650e

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

packages/jest-runtime/src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ export default class Runtime {
403403
specifier: string,
404404
referencingModule: VMModule,
405405
) => {
406+
invariant(
407+
runtimeSupportsVmModules,
408+
'You need to run with a version of node that supports ES Modules in the VM API. See https://jestjs.io/docs/en/ecmascript-modules',
409+
);
406410
const module = await this.resolveModule(
407411
specifier,
408412
referencingModule.identifier,
@@ -495,7 +499,7 @@ export default class Runtime {
495499
): Promise<void> {
496500
invariant(
497501
runtimeSupportsVmModules,
498-
'You need to run with a version of node that supports ES Modules in the VM API.',
502+
'You need to run with a version of node that supports ES Modules in the VM API. See https://jestjs.io/docs/en/ecmascript-modules',
499503
);
500504

501505
const [path, query] = (moduleName ?? '').split('?');
@@ -1209,6 +1213,11 @@ export default class Runtime {
12091213
filename: scriptFilename,
12101214
// @ts-expect-error: Experimental ESM API
12111215
importModuleDynamically: async (specifier: string) => {
1216+
invariant(
1217+
runtimeSupportsVmModules,
1218+
'You need to run with a version of node that supports ES Modules in the VM API. See https://jestjs.io/docs/en/ecmascript-modules',
1219+
);
1220+
12121221
const context = this._environment.getVmContext?.();
12131222

12141223
invariant(context, 'Test environment has been torn down');

0 commit comments

Comments
 (0)