Description
What happened?
Steps to Reproduce
import { W3CBaggagePropagator } from "@opentelemetry/core"
Expected Result
being able to compile and run the code
Actual Result
Runtime error:
SyntaxError: Named export 'W3CBaggagePropagator' not found. The requested module '@opentelemetry/core' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '@opentelemetry/core';
const { W3CBaggagePropagator } = pkg;
Notice how it says "is a CommonJS module" even though the package contains an ESM directory. I added "type": "module"
to node_modules/@opentelemetry/core/package.json
and I got a different error when compiling:
error TS2305: Module '"@opentelemetry/core"' has no exported member 'W3CBaggagePropagator'.
Additional Details
The ESM output is broken and doesn't follow ESM spec. First of all, the package.json does not contain "type": "module" so ES Modules will never be loaded from this package. And even if I add this line, the code inside ./build/esm is broken anyway.
For example, @opentelemetry/core/build/esm/index.d.ts has lines such as:
export * from './baggage/propagation/W3CBaggagePropagator';
This will not work in ESM because ESM requires the file extension to be in the import path. The line should be:
export * from './baggage/propagation/W3CBaggagePropagator.js';
I suggest you either fix the ESM output to make it actually functional, or remove it altogether. Because right now it just falls back to CJS. Maybe it works in its current state with some exotic bundlers, but it certainly doesn't follow the ESM spec.
OpenTelemetry Setup Code
No response
package.json
No response
Relevant log output
No response