Skip to content

Commit afb05bd

Browse files
fix: don't throw when typescript can't be resolved
1 parent 542b305 commit afb05bd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/utils/conditional-imports/ts-api-utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ const require = createRequire(import.meta.url);
88

99
export default (typescript === undefined
1010
? undefined
11-
: require("ts-api-utils")) as typeof tsApiUtils | undefined;
11+
: (() => {
12+
try {
13+
return require("ts-api-utils");
14+
} catch {
15+
return undefined;
16+
}
17+
})()) as typeof tsApiUtils | undefined;
1218

1319
// export default (await (() => {
1420
// if (ts !== undefined) {

src/utils/conditional-imports/typescript.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import type typescript from "typescript";
44

55
const require = createRequire(import.meta.url);
66

7-
export default require("typescript") as typeof typescript | undefined;
7+
export default (() => {
8+
try {
9+
return require("typescript");
10+
} catch {
11+
return undefined;
12+
}
13+
})() as typeof typescript | undefined;
814

915
// export default (await import("typescript")
1016
// .then((r) => r.default)

0 commit comments

Comments
 (0)