Skip to content

Commit 7202a72

Browse files
committed
Add fallback error handling for prism theme imports
- Add try-catch around dynamic prism theme imports in docusaurus config - Fallback to default prism-react-renderer themes if custom themes fail to load - Prevents CI failures when custom prism files have import issues - Ensures robust build process with graceful degradation
1 parent 7fa5845 commit 7202a72

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

demo/docusaurus.config.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,25 @@ const config = {
267267
};
268268

269269
async function createConfig() {
270-
const lightTheme = (await import("./src/utils/prismLight.mjs")).default;
271-
const darkTheme = (await import("./src/utils/prismDark.mjs")).default;
272-
// @ts-expect-error: we know it exists, right
273-
config.themeConfig.prism.theme = lightTheme;
274-
// @ts-expect-error: we know it exists, right
275-
config.themeConfig.prism.darkTheme = darkTheme;
270+
try {
271+
const lightTheme = (await import("./src/utils/prismLight.mjs")).default;
272+
const darkTheme = (await import("./src/utils/prismDark.mjs")).default;
273+
// @ts-expect-error: we know it exists, right
274+
config.themeConfig.prism.theme = lightTheme;
275+
// @ts-expect-error: we know it exists, right
276+
config.themeConfig.prism.darkTheme = darkTheme;
277+
} catch (error) {
278+
console.warn(
279+
"Failed to load custom prism themes, using defaults:",
280+
error.message
281+
);
282+
// Fallback to default themes from prism-react-renderer
283+
const { themes } = await import("prism-react-renderer");
284+
// @ts-expect-error: we know it exists, right
285+
config.themeConfig.prism.theme = themes.github;
286+
// @ts-expect-error: we know it exists, right
287+
config.themeConfig.prism.darkTheme = themes.vsDark;
288+
}
276289
return config;
277290
}
278291

0 commit comments

Comments
 (0)