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

Log warning when "target" is too high for the node version #1248

Open
2 tasks
Tracked by #1504
cspotcode opened this issue Feb 26, 2021 · 1 comment
Open
2 tasks
Tracked by #1504

Log warning when "target" is too high for the node version #1248

cspotcode opened this issue Feb 26, 2021 · 1 comment
Milestone

Comments

@cspotcode
Copy link
Collaborator

cspotcode commented Feb 26, 2021

Blocked by #1445

Building off of #1202, we know the maximum "target" you can use for the given node version, so we can log a helpful warning when your target is wrong:

Warning: You are using a "target" option that may be incompatible with your node version.
For node vXYZ we recommend "target": "es2018" or lower.
To disable this warning, add the following to your tsconfig:
    "ts-node": {"disableNodeCompatibilityWarnings": true}
To override your "target" within ts-node, add the following to your tsconfig:
    "ts-node": {"compilerOptions": {"target": "es2018"}}
To derive your tsconfig from a recommended set of options, add the following to your tsconfig:
    "extends": "ts-node/node12/tsconfig.json"

Questions

  • Should this warning be logged for programmatic usage? For ts-node/register? For --loader ts-node/esm? I don't think libraries should send output to stderr, but ts-node/register is a weird case because it's almost exclusively used from the CLI.
  • Should the disableNodeCompatibilityWarnings option be renamed to allow more than 2 modes?
    • `"forceNodeCompatibility": "auto" | "warn" | "off"
    • `"autoNodeCompatibility": "enabled" | "warn" | "disabled"
    • in auto / enabled mode, we override the "target" option with an appropriate value.
@cspotcode cspotcode changed the title Warning when "target" is too high for the node version Log warning when "target" is too high for the node version Feb 26, 2021
@cspotcode cspotcode added this to the next milestone May 15, 2021
@cspotcode
Copy link
Collaborator Author

cspotcode commented May 16, 2021

We discussed this on Discord: https://discord.com/channels/508357248330760243/508357707602853888/843546169752813589

Conclusions:

  • Use node's warnings API: process.emitWarning()
    • there is already precedent for warnings to emit to stderr from here
    • node already has APIs to intercept these warnings and flags to suppress them
  • Match node's behavior and emit each warning only once
  • Add warnings: boolean to API surface
    • false to disable them
    • Future work can expand to suppress or allow warnings by code
  • Add onWarning: callback to API surface
    • if specified, warnings are sent here instead of to process.emitWarning
  • All warnings get a code TSNODE<4-digit number>
    • This is familiar: node's deprecation warnings are DEP1234; TypeScript uses TS1234
    • code allows easy detection in process.on('warning' handlers

Questions

  • when tsconfig has "warnings": false, but a warning emits before tsconfig is loaded
    • Do we defer those warnings till after all options are known? For the "target" warning, we can do this

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

1 participant