Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find name 'Buffer' error after installing Tesseract.js in Angular

I need Tesseract in my project so first I used yarn add tesseract.js after that I used yarn add --dev @types/tesseract.js. When I try to use ng serve I get the following error:

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;

Anyone knows how to fix this? Thanks in advance

like image 508
Gavin Hartog Avatar asked Jan 25 '26 13:01

Gavin Hartog


1 Answers

I was able to resolve this issue by adding types: ["node"] to the compilerOptions in tsconfig.app.json file.

{
  ...
  "compilerOptions": {
    ...
    "types": ["node"] // <-- This should do the charm.
  },
  ...
}
like image 142
Harish Avatar answered Jan 27 '26 05:01

Harish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!