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

--unstable-node-globals fails with --check option #27013

Open
SebastienGllmt opened this issue Nov 22, 2024 · 2 comments
Open

--unstable-node-globals fails with --check option #27013

SebastienGllmt opened this issue Nov 22, 2024 · 2 comments
Labels
bug Something isn't working correctly tsc related to the TypeScript tsc compiler

Comments

@SebastienGllmt
Copy link

To support libraries that use node global variables, a new --unstable-node-globals variable was added in #26611

However, using this flag with the --check flag fails because Typescript (and the IDE) isn't aware of this flag

Ex: if you have the following code

type Foo = Buffer;

It will fail with

TS2580 [ERROR]: Cannot find name 'Buffer'.
type Foo = Buffer;

This can be fixed by adding the following to your project

declare global {
  type Buffer = typeof import("node:buffer").Buffer;
}

Or (possibly?) with specifying some lib settings. Ideally somehow Deno would know to make this work if you use the flag (but I don't see how the IDE could know this), or at least make a more useful error message that tells you to change your deno.json file to fix this error

@dsherret dsherret added bug Something isn't working correctly tsc related to the TypeScript tsc compiler labels Nov 23, 2024
@dsherret
Copy link
Member

In this scenario, we need to call ts.deno.setNodeOnlyGlobalNames again and provide a new set of globals:

https://github.com/denoland/deno/blob/12b377247be2b74155ded3a678ff2996ef3d7c9f/cli/tsc/99_main_compiler.js#L1344C11-L1344C33

@SebastienGllmt
Copy link
Author

SebastienGllmt commented Nov 25, 2024

This can be fixed by adding declare global to your project

I actually think this is not a great solution because of this JSR issue where JSR doesn't support declare global yet: #23427

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly tsc related to the TypeScript tsc compiler
Projects
None yet
Development

No branches or pull requests

2 participants