fix: import type + lazy singleton pour dagre et pptxgenjs (Turbopack build)
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 23s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Antigravity
2026-05-05 21:48:54 +00:00
parent 4f950740eb
commit 7326cfc98f
2 changed files with 29 additions and 8 deletions

View File

@@ -4,7 +4,16 @@ import { tool } from 'ai'
import { z } from 'zod'
import { toolRegistry } from './registry'
import { prisma } from '@/lib/prisma'
import dagre from 'dagre'
// import type is erased at build time — Turbopack won't try to resolve the module
import type dagreType from 'dagre'
let _dagre: typeof dagreType | null = null
async function getDagre(): Promise<typeof dagreType> {
if (!_dagre) {
const mod = await import('dagre')
_dagre = (mod.default ?? mod) as typeof dagreType
}
return _dagre
}
interface SimplifiedNode {
id: string
@@ -504,12 +513,13 @@ function getNodeRenderSpec(node: SimplifiedNode, isCenter: boolean): NodeRenderS
return { text: wrapped, fontSize, width, height }
}
function computeNodeLayoutForRankdir(
async function computeNodeLayoutForRankdir(
nodes: SimplifiedNode[],
edges: SimplifiedEdge[],
rankdir: 'LR' | 'TB',
renderSpecs: Map<string, NodeRenderSpec>,
): Map<string, NodeLayoutBox> {
): Promise<Map<string, NodeLayoutBox>> {
const dagre = await getDagre()
const graph = new dagre.graphlib.Graph()
graph.setGraph({
rankdir,
@@ -738,11 +748,11 @@ async function computeNodeLayout(
const firstRankdir: 'LR' | 'TB' = (diagramType === 'org-chart') ? 'TB' : 'LR'
const secondRankdir: 'LR' | 'TB' = firstRankdir === 'LR' ? 'TB' : 'LR'
const lrLayout = computeNodeLayoutForRankdir(nodes, edges, firstRankdir, renderSpecs)
const lrLayout = await computeNodeLayoutForRankdir(nodes, edges, firstRankdir, renderSpecs)
const lrQuality = computeLayoutQuality(nodes, edges, lrLayout)
const lrBounds = getLayoutBounds(lrLayout)
const tbLayout = computeNodeLayoutForRankdir(nodes, edges, secondRankdir, renderSpecs)
const tbLayout = await computeNodeLayoutForRankdir(nodes, edges, secondRankdir, renderSpecs)
const tbQuality = computeLayoutQuality(nodes, edges, tbLayout)
const tbBounds = getLayoutBounds(tbLayout)

View File

@@ -1,6 +1,16 @@
'use server'
import PptxGenJS from 'pptxgenjs'
// import type is erased at build time — Turbopack won't try to resolve the module
import type PptxGenJSModule from 'pptxgenjs'
// Lazy singleton — actual module loaded at runtime only
let _PptxGenJS: (new () => PptxGenJSModule) | null = null
async function getPptxGenClass(): Promise<new () => PptxGenJSModule> {
if (!_PptxGenJS) {
const mod = await import('pptxgenjs')
_PptxGenJS = (mod.default ?? mod) as unknown as new () => PptxGenJSModule
}
return _PptxGenJS
}
import { tool } from 'ai'
import { z } from 'zod'
import { toolRegistry } from './registry'
@@ -960,10 +970,11 @@ function addClosingSlide(pres: PptxGenJS, spec: PresentationSpec, t: Theme, styl
return s
}
function buildPresentation(spec: PresentationSpec): PptxGenJS {
async function buildPresentation(spec: PresentationSpec): Promise<PptxGenJSModule> {
const { theme } = resolveTheme(spec)
const style = STYLES[spec.style || 'soft'] || STYLES.soft!
const PptxGenJS = await getPptxGenClass()
const pres = new PptxGenJS()
pres.title = spec.title
pres.author = 'Momento'
@@ -1131,7 +1142,7 @@ RULES:
}
}
const pptx = buildPresentation(spec)
const pptx = await buildPresentation(spec)
const base64 = await pptx.write({ outputType: 'base64' }) as string
const canvas = await prisma.canvas.create({