From 0b60f7b4fc5c672500dcd7ad2a0cd595ab038012 Mon Sep 17 00:00:00 2001 From: Drew Hess Date: Sat, 25 Jun 2022 17:53:15 +0100 Subject: [PATCH] fix(dagre): Tell vite (or, actually, rollup) not to ignore try/catch. Judging from https://github.com/vitejs/vite/issues/5759, this should fix the Chromatic issue we've been having with dagre, and if so, will also fix a problem we *would* have had with a production build of our own app once we tried to render React Flow trees. --- packages/primer-components/.storybook/main.js | 10 ++++++++++ packages/primer-components/vite.config.ts | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/packages/primer-components/.storybook/main.js b/packages/primer-components/.storybook/main.js index 3e90bd89..7449b462 100644 --- a/packages/primer-components/.storybook/main.js +++ b/packages/primer-components/.storybook/main.js @@ -20,6 +20,16 @@ module.exports = { plugins: [...config.plugins, svgr(), tsconfigPaths()], // Don't write to node_modules, in case someday we can get it from Nix. cacheDir: "../.vite", + build: { + ...config.build, + + // Workaround a dagre issue. See: + // + // https://github.com/vitejs/vite/issues/5759#issuecomment-1034461225 + commonjsOptions: { + ignoreTryCatch: false, + }, + }, }; }, }; diff --git a/packages/primer-components/vite.config.ts b/packages/primer-components/vite.config.ts index 03cdd155..281bb775 100644 --- a/packages/primer-components/vite.config.ts +++ b/packages/primer-components/vite.config.ts @@ -57,6 +57,13 @@ export default defineConfig({ // XXX dhess: do we need to add Tailwind UI deps here? external: ["react", "react-dom", "react-router-dom"], }, + + // Workaround a dagre issue. See: + // + // https://github.com/vitejs/vite/issues/5759#issuecomment-1034461225 + commonjsOptions: { + ignoreTryCatch: false, + } }, define: {