fix(build): Enable esModuleInterop for improved compatibility #4519
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which problem is this PR solving?
I ran into issues instrumenting code with the import-in-the-middle package whilst using the bundler esbuild (to bundle my telemetry code - not modules I wanted to trace). I noticed that the import looked like
As flagged in issue #3954 this relies on some incorrect assumptions typescript makes about module bundling.
A detailed description of these wrong assumptions can be found here: https://www.typescriptlang.org/tsconfig#esModuleInterop.
The tldr is
import * as moment from "moment"
is not the same asconst moment = require("moment")
Turning on esModuleInterop fixes these problems but required a few updates across the codebase that I believe will not change the behavior of the packages
Fixes #3954
Short description of the changes
Turned on esModuleInterop in the base tsconfig.
Fixed the imports so that where the default import is desired we
import Mod from 'mod'
and when the module doesn't have a default import we stick withimport * as Mod from 'mod'
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
I have ran the tests and tscompiler to check that things still work. I still would like to import this into an existing project using opentelemetry and check there are no issues. I'm not familiar with doing this on a project so large - guidance welcome here 😄
Checklist: