angular - 在 Angular 中安装 Tesseract.js 后找不到名称 'Buffer' 错误

标签 angular tesseract yarnpkg

我的项目中需要 Tesseract,所以首先我使用了 yarn add tesseract.js,然后我使用了 yarn add --dev @types/tesseract.js。当我尝试使用 ng serve 时,出现以下错误:

ERROR in node_modules/tesseract.js/src/index.d.ts:98:60 - error TS2591: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.

98     | CanvasRenderingContext2D | File | Blob | ImageData | Buffer;

有人知道怎么解决吗?提前致谢

最佳答案

我能够通过将 types: ["node"] 添加到 tsconfig.app.json 文件中的 compilerOptions 来解决这个问题.

{
  ...
  "compilerOptions": {
    ...
    "types": ["node"] // <-- This should do the charm.
  },
  ...
}

关于angular - 在 Angular 中安装 Tesseract.js 后找不到名称 'Buffer' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60322215/

相关文章:

javascript - react native git 升级错误 : fatal: No remote repository specified

validation - 自定义异步验证在返回 promise 时不起作用

android - 带燃气表的 Tesseract OCR

ios - Tesseract 崩溃了

node.js - 从 NPM 包中导出多个模块

React-Native - 无法从 node_modules/eslint/lib/cli-engine/cli-engine.js 解析模块 fs

css - Angular Material2 并非所有样式都适用

javascript - 无法读取未定义的属性 'Push' - Typescript

angular - 错误 : No Component Factory Found. 是否添加到@NgModule.entryComponents?

ocr - 使用 OCR 识别上标字符