Skip to content

DOCXKIT_PLUGIN_RENDER_FAILED: 插件渲染失败 ​

插件 render 方法抛错,或 PDK 渲染断言拒绝其输出。

修复步骤 ​

  1. 在本地检查原始 cause,并核对插件选项。
  2. render 返回受支持的 docx 元素。
  3. PDK 断言失败时核对预期元素类型和数量。

问题示例 ​

ts
import { createDocx, definePlugin } from 'docx-kit'

const plugin = definePlugin({
  name: 'example', render() { throw new Error('Resource unavailable') },
})
await createDocx().use(plugin).plugin('example', {}).toBlob()

修复示例 ​

ts
import { createDocx, definePlugin } from 'docx-kit'
import { Paragraph } from 'docx'

const plugin = definePlugin({
  name: 'example', render: () => new Paragraph('Hello'),
})
const blob = await createDocx().use(plugin).plugin('example', {}).toBlob()

常见原因 ​

  • 渲染器异常、选项无效,或 PDK 输出类型不符。

诊断字段 ​

消息示例 ​

text
Plugin render failed: example

源码与相关指南 ​

Released under the MIT License.