diff --git a/packages/include/src/index.ts b/packages/include/src/index.ts index 7355b11cc5e26..004d175ab9f69 100644 --- a/packages/include/src/index.ts +++ b/packages/include/src/index.ts @@ -21,28 +21,17 @@ const jiti = createJITI( * If the module at {@link path} is not found, `null` will be returned. */ export async function include(path: string): Promise { - try { - const module = await jiti.import(path, {}); - if (!module) { - throw new Error('Included module is empty'); - } - if (typeof module !== 'object') { - throw new Error(`Included module is not an object, is instead "${typeof module}"`); - } - if ('default' in module) { - return module.default as T; - } - return module as T; - } catch (err) { - // NOTE: we dont use the err.code because maybe the included module is importing another module that does not exist. - // if we were to use the MODULE_NOT_FOUND code, then those includes will fail with an unclear error - if (String(err).includes(`Cannot find module '${path}'`)) { - // - } else { - throw err; - } + const module = await jiti.import(path, {}); + if (!module) { + throw new Error('Included module is empty'); + } + if (typeof module !== 'object') { + throw new Error(`Included module is not an object, is instead "${typeof module}"`); + } + if ('default' in module) { + return module.default as T; } - return null; + return module as T; } export interface RegisterTsconfigPathsOptions {