MCPcopy Create free account
hub / github.com/NomicFoundation/hardhat / loadModule

Function loadModule

packages/hardhat-verify/src/internal/module.ts:22–54  ·  view source on GitHub ↗
(
  modulePath: string,
)

Source from the content-addressed store, hash-verified

20 * - ERR_IMPORT_MODULE_FAILED for any other import/runtime error
21 */
22export async function loadModule(
23 modulePath: string,
24): Promise<Record<string, unknown>> {
25 const moduleAbsolutePath = path.resolve(process.cwd(), modulePath);
26
27 try {
28 const moduleUrl = pathToFileURL(moduleAbsolutePath).href;
29 const importedModule: Record<string, unknown> = await import(moduleUrl);
30
31 return importedModule;
32 } catch (error) {
33 ensureError(error);
34
35 if ("code" in error && error.code === "ERR_MODULE_NOT_FOUND") {
36 throw new HardhatError(
37 HardhatError.ERRORS.HARDHAT_VERIFY.VALIDATION.MODULE_NOT_FOUND,
38 { modulePath },
39 );
40 }
41
42 if (error instanceof SyntaxError) {
43 throw new HardhatError(
44 HardhatError.ERRORS.HARDHAT_VERIFY.VALIDATION.MODULE_SYNTAX_ERROR,
45 { modulePath, errorMessage: error.message },
46 );
47 }
48
49 throw new HardhatError(
50 HardhatError.ERRORS.HARDHAT_VERIFY.VALIDATION.IMPORT_MODULE_FAILED,
51 { modulePath, errorMessage: error.message },
52 );
53 }
54}

Callers 3

module.tsFile · 0.50
resolveConstructorArgsFunction · 0.50
resolveLibrariesFunction · 0.50

Calls 2

ensureErrorFunction · 0.90
resolveMethod · 0.45

Tested by

no test coverage detected