tiny-editor icon indicating copy to clipboard operation
tiny-editor copied to clipboard

🐛 [Bug]: cannot npm start in Angular project, TS2307: Cannot find module 'html2canvas' or its corresponding type declaration.

Open kagol opened this issue 3 months ago • 1 comments

Version

latest

Link to minimal reproduction

在一个 Angular 项目中,安装 @opentiny/fluent-editor,然后本地启动报错:

Error: node_modules/@opentiny/fluent-editor/types/tools/screenshot.d.ts:1:71 - error TS2307: Cannot find module 'html2canvas' or its corresponding type declaration.

import { default as html2canvas, Options as Html2CanvasOptions } from 'html2canvas';

其实并没有配置 screenshot 模块,也没有安装 html2canvas 依赖。

该问题在 Vite + Vue 项目里不会出现。

Step to reproduce

如上

What is expected

No response

What is actually happening

No response

What is your project name

Wiki

Any additional comments (optional)

No response

kagol avatar Sep 01 '25 13:09 kagol

解决方法:

新建文件 src/shims/html2canvas.d.ts

// shims/html2canvas.d.ts 屏蔽引入@opentiny/fluent-editor, 但未安装html2canvas报错
declare module 'html2canvas' {
  // 默认导出的函数
  const html2canvas: (
    element: Element,
    options?: Options
  ) => Promise<HTMLCanvasElement>;

  // 命名空间或接口导出
  namespace html2canvas {
    export interface Options {
      // 根据实际需求定义 Options 的属性
      logging?: boolean;
      imageTimeout?: number;
      // 其他可能的属性...
    }
  }

  // 导出 Options 接口
  export { html2canvas };
  export type Options = html2canvas.Options;
  export default html2canvas;
}

由于未开启 screenshot 功能,因此不需要安装 html2canvas

kagol avatar Sep 03 '25 01:09 kagol