File tree Expand file tree Collapse file tree
packages/shared/tracing/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,14 +14,20 @@ let otelModulePromise: Promise<any | null> | null = null
1414// be installed in the consumer app; we look it up purely at runtime.
1515const OTEL_PKG = '@opentelemetry/api'
1616
17+ // Wrap import() in a Function constructor so the import() expression is
18+ // never present as syntax in the bundled output. hermesc (the Hermes bytecode
19+ // compiler used by React Native release builds) rejects import() at parse
20+ // time — before any dead-code elimination — so the syntax must be physically
21+ // absent from the bundle. new Function() bodies are opaque strings to all
22+ // static parsers, including hermesc.
23+ // eslint-disable-next-line no-new-func
24+ const _dynamicImport = new Function ( 'p' , 'return import(p)' ) as (
25+ pkg : string
26+ ) => Promise < any >
27+
1728function loadOtel ( ) : Promise < any | null > {
1829 if ( otelModulePromise === null ) {
19- // The variable specifier + magic comments together cover every common
20- // bundler. Webpack/Turbopack honor the ignore comments; bundlers that
21- // ignore the comments still bail out on the non-literal specifier.
22- otelModulePromise = import (
23- /* webpackIgnore: true */ /* @vite -ignore */ /* turbopackIgnore: true */ OTEL_PKG
24- ) . catch ( ( ) => null )
30+ otelModulePromise = _dynamicImport ( OTEL_PKG ) . catch ( ( ) => null )
2531 }
2632 return otelModulePromise
2733}
You can’t perform that action at this time.
0 commit comments