Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find name 'Buffer' #978

Closed
MikeDabrowski opened this issue Jan 27, 2025 · 9 comments
Closed

Cannot find name 'Buffer' #978

MikeDabrowski opened this issue Jan 27, 2025 · 9 comments

Comments

@MikeDabrowski
Copy link

MikeDabrowski commented Jan 27, 2025

We are using pdfjs which uses this lib. Recently we are trying to update to latest version which runs on typescript 5.7. But the builds do not work because of this bug. Is there any workaround ?

Our project already has latest node typings and

"@types/node": "^22.10.10",

"types": ["node"],
"typeRoots": ["node_modules/@types"]

Here are the error examples:

X [ERROR] TS2591: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try
 `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig. [plugin angular-compiler]

    node_modules/@napi-rs/canvas/index.d.ts:444:60:
      444 │ export function convertSVGTextToPath(svg: Buffer | string): Buffer
          ╵                                                             ~~~~~~


X [ERROR] TS2307: Cannot find module 'http' or its corresponding type declarations. [plugin angular-compiler]

    node_modules/@napi-rs/canvas/index.d.ts:449:26:
      449 │   requestOptions?: import('http').RequestOptions
          ╵                           ~~~~~~


X [ERROR] TS2591: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try
 `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig. [plugin angular-compiler]

    node_modules/@napi-rs/canvas/index.d.ts:453:25:
      453 │   source: string | URL | Buffer | ArrayBufferLike | Uint8Array | ...
          ╵                          ~~~~~~


X [ERROR] TS2307: Cannot find module 'stream' or its corresponding type declarations. [plugin angular-compiler]

    node_modules/@napi-rs/canvas/index.d.ts:453:80:
      453 │ ...ArrayBufferLike | Uint8Array | Image | import('stream').Readable,
          ╵                                                  ~~~~~~~~
@Brooooooklyn
Copy link
Owner

You can either:

  • add skipLibCheck: true to your tsconfig.json
  • or npm i --save-dev @types/node

@MikeDabrowski
Copy link
Author

MikeDabrowski commented Jan 28, 2025 via email

@Brooooooklyn
Copy link
Owner

Have you tried npm i --save-dev @types/node ?

@MikeDabrowski
Copy link
Author

Yes that is what I meant.

"@types/node": "^22.10.10",

I am still debugging this. I created empty angular 19 repo and have not yet encountered the same issue.

@MikeDabrowski
Copy link
Author

Here is the repro https://stackblitz.com/edit/node-apbsp4rj?file=tsconfig.json

skipLibCheck works but is not desired.

@Brooooooklyn
Copy link
Owner

@MikeDabrowski add "types": ["node"] into the tsconfig.app.json can fix your bug

@MikeDabrowski
Copy link
Author

MikeDabrowski commented Feb 2, 2025

No, adding types: ["node"] does not fix the issue. I do not agree with marking this as 'completed'. Have you even tried it yourself?

I have modified the stackblitz and still getting the same error. The only workaround that works is skipLibCheck which is not desired because it skips checking all other libraries as well.

@Brooooooklyn
Copy link
Owner

@MikeDabrowski I don't have any typecheck issues in your stackblitz project anymore

Have you even tried it yourself?

I have tried with pure npm/TypeScript project and it works fine, so I don't think it's a bug from @napi-rs/canvas

Image

@MikeDabrowski
Copy link
Author

@Brooooooklyn It is really weird. I also no longer have this errors in the stackblitz. Even after removing types: ["node"] and running both start and start:ci.

I just did a check in my project. I removed skipLibCheck and it still worked. Then removed types: ["node"] and it finally broke again.

In the stackblitz I fixed all versions and tried again with no types and no skipLibCheck - still passes. But in my project I need to have types: ["node"] in tsconfig. I also think that extends overwrites the types from base config rather than concatenating the arrays.

I can't explain what happened, but as you said - types: ["node"] usually helps. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants