sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

chore(dev): Fix ts-node compatibility issues

Open lobsterkatie opened this issue 3 years ago • 2 comments

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 module tsconfig option to be set to commonjs, 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 using import * as ____, import { default as ___ }, or import ____ syntax, and need to be required instead. Setting esModuleInterop fixes 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.

lobsterkatie avatar May 10 '22 21:05 lobsterkatie

The way I understand our current test setup, jest takes the tsconfig.test.json from each package. Couldn't we set the esModuleInterop there?

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?

lobsterkatie avatar Jun 17 '22 19:06 lobsterkatie

Yeah can't remember why I wrote that. I disagree with past Luca. Feel free to ignore my comment 😵‍💫

lforst avatar Jun 20 '22 07:06 lforst