Skip to content

Commit abf8745

Browse files
committed
Fix @dagrejs/dagre "module is not defined" SSR error
Move @dagrejs/dagre to ssr.external instead of ssr.optimizeDeps.include. The experimental ssr.optimizeDeps pre-bundling wasn't converting the CJS module to ESM. Externalizing lets Node.js load it natively as CJS.
1 parent eedaca4 commit abf8745

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

docs/vite.config.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,8 @@ export default defineConfig({
9696
// Disabled during tests to avoid "Failed to load source map" warnings (e.g. typescript.js.map)
9797
// Ref: https://github.com/vitest-dev/vitest/issues/6806
9898
noExternal: isTest ? undefined : true,
99-
// satori and @resvg/resvg-js have CJS dependencies that need to be loaded as external
100-
external: ['satori', '@resvg/resvg-js'],
101-
// @dagrejs/dagre is CJS-only and fails with "module is not defined" when
102-
// bundled for SSR. Pre-bundling converts it to ESM so it works both in
103-
// dev and in the production build (where node_modules aren't available).
104-
optimizeDeps: {
105-
include: ['@dagrejs/dagre']
106-
}
99+
// CJS-only packages that fail with "module is not defined" in Vite's ESM
100+
// module runner. Externalizing lets Node.js load them natively as CJS.
101+
external: ['satori', '@resvg/resvg-js', '@dagrejs/dagre']
107102
}
108103
});

0 commit comments

Comments
 (0)