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

Node types can be used in any package #5834

Closed
timfish opened this issue Sep 27, 2022 · 4 comments
Closed

Node types can be used in any package #5834

timfish opened this issue Sep 27, 2022 · 4 comments

Comments

@timfish
Copy link
Collaborator

timfish commented Sep 27, 2022

Steps to Reproduce

Go into any file in @sentry/utils and add a reference to global.process.version and no error is reported during TypeScript compilation.

But why?

Following the definitions in vscode, I suspect this is due to @types/node in the root node_modules. TypeScript loads everything in @types/* automatically and appears to use node module resolution traversal.

Solutions?

If I remove @types/node from the root package.json the package is remains there due to hoisting but the version changes to v17 rather than the current 10.17.56 which is even worse. We may be able to work around this via the yarn workspace nohoist option.

We may be able to improve the situation by adding global to the no-restricted-globals eslint rule.

@timfish
Copy link
Collaborator Author

timfish commented Sep 27, 2022

Well nohoist doesn't work.

TypeScript now picks up node types from:
./node_modules/@types/accepts/node_modules/@types/node/globals.global.d.ts

It looks like this can be fixed via tsconfig.json with an empty array for types:

  "compilerOptions": {
    "types": []
  }

But much like #5816, this should really be the default and node types should be enabled only where they're required, rather than selectively disabled for packages where they're not required.

Obviously this is all complicated by the fact that ts-node defaults to tsconfig.json and all scripts use node.js functionality.

@lforst
Copy link
Member

lforst commented Sep 27, 2022

We can configure an environment via eslint: https://eslint.org/docs/latest/user-guide/configuring/language-options Maybe shared-node-browser works for us?

We would then also have to turn on the no-undef rule that is turned off with typescript-eslint-recommended: typescript-eslint/typescript-eslint#4580 (comment)

@lforst
Copy link
Member

lforst commented Sep 27, 2022

Also if our tsconfigs cause problems, we can always shuffle them around or pass the --project flag to ts-node

@mydea
Copy link
Member

mydea commented Mar 3, 2023

Why was this issue closed?

While we think it would be helpful to solve this issue, we're busy with a lot of other tasks at the moment.
Therefore, this issue is not a priority for us at this time.
If you still want to see this resolved, please consider opening a PR for it - we're always happy to review them.

Please feel free to leave a comment if you think this issue should be reopened.

@mydea mydea closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants