We recently exported a const enum: export const enum SemconvStability from #5684, released in @opentelemetry/instrumentation@0.201.0. From a quick look, there are no other const enum exports from packages in this repo.
TIL exporting a const enum from a package is problematic for some usages of the package. https://ncjamieson.com/dont-export-const-enums/ explains the issue. Some tooling will compile TS modules one file at a time in isolation. In those cases, a const enum reference, e.g. SemconvStability.OLD, cannot be resolved. One such tooling example is ts-node being used by mocha for testing in opentelemetry-js.git and opentelemetry-js-contrib.git. I gather that this was not an issue for usage of SemconvStability in the same repo (e.g. in instr-http, instr-xhr, instr-fetch), because it is a monorepo where the dependencies are symlinks to the source dir.
We hit the error in this PR, the first one in opentelemetry-js-contrib to attempt to use SemconvStability: open-telemetry/opentelemetry-js-contrib#2671 (comment)
To fix this:
We recently exported a
const enum:export const enum SemconvStabilityfrom #5684, released in@opentelemetry/instrumentation@0.201.0. From a quick look, there are no otherconst enumexports from packages in this repo.TIL exporting a
const enumfrom a package is problematic for some usages of the package. https://ncjamieson.com/dont-export-const-enums/ explains the issue. Some tooling will compile TS modules one file at a time in isolation. In those cases, a const enum reference, e.g.SemconvStability.OLD, cannot be resolved. One such tooling example ists-nodebeing used by mocha for testing in opentelemetry-js.git and opentelemetry-js-contrib.git. I gather that this was not an issue for usage ofSemconvStabilityin the same repo (e.g. in instr-http, instr-xhr, instr-fetch), because it is a monorepo where the dependencies are symlinks to the source dir.We hit the error in this PR, the first one in opentelemetry-js-contrib to attempt to use
SemconvStability: open-telemetry/opentelemetry-js-contrib#2671 (comment)To fix this:
const enumtoenum. I've confirmed this fixes the testing issue for the instrumentation-knex PR above. fix(instrumentation): changeSemconvStabilityexport fromconst enumtoenum#5692isolatedModules: trueto our tsconfig.json in the opentelemetry-js repo. This config is suggested in the blog post above as a way to guard against exporting const enums. Adding this config also means dealing with a number (153) of cases oferror TS1205: Re-exporting a type when 'isolatedModules' is enabled requires using 'export type'.in our packages, so this is a larger change. (See chore: enable tsconfig isolatedModules #5697)isolatedModulescompilation option opentelemetry-js-contrib#2839 for contrib repo