diff --git a/web-admin/src/utils/crm/contract-html-to-docx.ts b/web-admin/src/utils/crm/contract-html-to-docx.ts
index 35a73e7c1..7501e4f00 100644
--- a/web-admin/src/utils/crm/contract-html-to-docx.ts
+++ b/web-admin/src/utils/crm/contract-html-to-docx.ts
@@ -1,9 +1,16 @@
/** 合同打印弹窗:HTML → DOCX 预处理与生成 */
-import HTMLtoDOCX from '@turbodocx/html-to-docx'
+import htmlToDocxModule from '@turbodocx/html-to-docx'
const DOCX_MIME = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
+/** CJS/ESM 互操作:Vite/浏览器多为函数,tsx/Node 偶发 `{ default: fn }` */
+const HTMLtoDOCX = (
+ typeof htmlToDocxModule === 'function'
+ ? htmlToDocxModule
+ : (htmlToDocxModule as { default?: unknown })?.default
+) as (htmlString: string, headerHTMLString?: string | null, documentOptions?: Record, footerHTMLString?: string | null) => Promise
+
/**
* 将已预处理的合同 HTML 转为 DOCX Blob(浏览器下载用)。
* 调用方须先执行 prepareContractHtmlForDocx。
@@ -12,6 +19,10 @@ export async function generateContractDocxBlob(
preparedHtml: string,
title?: string
): Promise {
+ if (typeof HTMLtoDOCX !== 'function') {
+ throw new Error('html-to-docx 加载失败:未获得可调用的转换函数')
+ }
+
const fullHtml = `${preparedHtml}`
const result = await HTMLtoDOCX(fullHtml, null, {
orientation: 'portrait',