signalfx/splunk-otel-js-web

Typescript - No types published for library

Closed this issue · 3 comments

I am working with an Internal Angular app with my enterprise. Unfortunately we've been having trouble getting any type support.

Application Details
Angular 14
Typescript 4.8
Node 16
ES 2020

Library Details:
Tested versions 12.3 thru 14rc5

Using the library with no changes results in the following error:

TypeError: _splunk_otel_web__WEBPACK_IMPORTED_MODULE_0__.init is not a function

In order to resolve, types must be written by the consumer and added to the tsconfig typeRoots property. This is trickier as we wrap otel-web in another internal lib. Is there any way to get native types from the lib or contributing the full types to the DefinitelyTyped project?

Additionally some of our unit tests will fail without placing this reference to the library in tsconfig path which I suspect may be related to the types issue.
"paths": { "@splunk/otel-web": ["node_modules/@splunk/otel-web/dist/cjs/index.js"] },

t2t2 commented

There's typescript definitions included in the package (/@splunk/otel-web/dist/cjs/index.d.ts) that gets automatically loaded by typescript:

image

So that's quite odd, got any minimal repo of this setup that you could share?

Unit tests failure is probably from us currently only exporting via browser and module fields, there's some plans to improve compatibility (including server side rendering cases) but I don't have a concrete estimate to give right now

Sorry for the delay - I was working on creating a very basic Angular repo to reproduce the issue, but when I finally trimmed it down and used the library directly (no methods in a secondary npm package) there were no issues with it finding the types correctly and initializing. I'm going to continue researching/troubleshooting the situation when it is used from within an internal npm package and report back.

An update: We were able to resolve this issue with a simple import change. I'm not sure if this is mentioned anywhere in the splunk otel docs.

Replaced this import:
import SplunkOtelWeb from '@splunk/otel-web';

With this:
import { SplunkRum } from '@splunk/otel-web';

Thanks to the splunk team for their assistance with this!