diff --git a/src/loader/egg_loader.ts b/src/loader/egg_loader.ts index 8edb1558..e962ab54 100644 --- a/src/loader/egg_loader.ts +++ b/src/loader/egg_loader.ts @@ -2,7 +2,7 @@ import fs from 'node:fs'; import path from 'node:path'; import assert from 'node:assert'; import { debuglog, inspect } from 'node:util'; -import { isAsyncFunction, isClass, isGeneratorFunction, isObject } from 'is-type-of'; +import is, { isAsyncFunction, isClass, isGeneratorFunction, isObject } from 'is-type-of'; import homedir from 'node-homedir'; import type { Logger } from 'egg-logger'; import { getParamNames, readJSONSync } from 'utility'; @@ -1421,6 +1421,9 @@ export class EggLoader { let mod = await this.requireFile(fullpath); if (typeof mod === 'function' && !isClass(mod)) { mod = mod(...inject); + if (is.promise(mod)) { + mod = await mod; + } } return mod; }