diff --git a/src/utils/conditional-imports/ts-api-utils.ts b/src/utils/conditional-imports/ts-api-utils.ts index 83621fae0..9a9ee4f63 100644 --- a/src/utils/conditional-imports/ts-api-utils.ts +++ b/src/utils/conditional-imports/ts-api-utils.ts @@ -8,7 +8,13 @@ const require = createRequire(import.meta.url); export default (typescript === undefined ? undefined - : require("ts-api-utils")) as typeof tsApiUtils | undefined; + : (() => { + try { + return require("ts-api-utils"); + } catch { + return undefined; + } + })()) as typeof tsApiUtils | undefined; // export default (await (() => { // if (ts !== undefined) { diff --git a/src/utils/conditional-imports/typescript.ts b/src/utils/conditional-imports/typescript.ts index 2bda12684..66bd4dc17 100644 --- a/src/utils/conditional-imports/typescript.ts +++ b/src/utils/conditional-imports/typescript.ts @@ -4,7 +4,13 @@ import type typescript from "typescript"; const require = createRequire(import.meta.url); -export default require("typescript") as typeof typescript | undefined; +export default (() => { + try { + return require("typescript"); + } catch { + return undefined; + } +})() as typeof typescript | undefined; // export default (await import("typescript") // .then((r) => r.default)