sentry-javascript
sentry-javascript copied to clipboard
chore(dev): Fix ts-node compatibility issues
WIP
Moving this back to draft because it's going to take a little more work than I thought to fix the currently failing tests.
This fixes two compatibility issues with ts-node:
- Older versions of Node need the
moduletsconfig option to be set tocommonjs, so that ts-node will do that conversion before running a script, since those old Node versions can't handle ESM modules. - Certain third-party packages (ones which use the
exports = <some function>pattern, for example) can't be accessed usingimport * as ____,import { default as ___ }, orimport ____syntax, and need to be required instead. SettingesModuleInteropfixes that, though, so we don't have to worry about the implementation details of the package when we import it.
These options are both set in the dev tsconfig, but that's only helpful if ts-node knows to use it. In order to not have to specify in every yarn script which uses ts-node which config to use, this takes advantage of yarn's (bizarrely undocumented) ability to set environment variables in order to point to the correct config file globally.
The way I understand our current test setup, jest takes the
tsconfig.test.jsonfrom each package. Couldn't we set theesModuleInteropthere?
Though it's true that my goal is eventually to have tests all read from this dev tsconfig, for now they do in fact use the config in their package. So for now at least this doesn't affect tests, only ts-node scripts.
I'm also curious, though - even if it were about tests, why would it be better to set esModuleInterop in many places rather than one central place?
Yeah can't remember why I wrote that. I disagree with past Luca. Feel free to ignore my comment 😵💫