opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

Tell opentelemtry-js build for nativescript to target browser platform

Open eighteight opened this issue 3 years ago • 1 comments
trafficstars

  • [ x] This only affects the JavaScript OpenTelemetry library
  • [ x] This may affect other libraries, but I would like to get opinions here first

I implementing an OT tracer in the mobile nativescript (based on angular.js, which can be vanilla javascript, vue.js etc) and am following the path of instrumenting a web angular application. The build fails with the errors, for example:

ERROR in ./node_modules/@opentelemetry/core/build/esm/platform/node/environment.js 16:0-25
Module not found: Error: Can't resolve 'os' in '/Users/eigh_io/genotek/genotek-app/node_modules/@opentelemetry/core/build/esm/platform/node'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
        - install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "os": false }
 @ ./node_modules/@opentelemetry/core/build/esm/platform/node/index.js 16:0-30 16:0-30
 @ ./node_modules/@opentelemetry/core/build/esm/platform/index.js 16:0-23 16:0-23
 @ ./node_modules/@opentelemetry/core/build/esm/index.js 27:0-27 27:0-27
 @ ./node_modules/@jufab/opentelemetry-angular-interceptor/fesm2015/jufab-opentelemetry-angular-interceptor.js 7:0-180 108:12-24 233:23-41 233:54-69 236:23-41 236:54-70 239:23-41 239:54-78 628:19-44 718:19-38 960:23-41 960:54-69 963:23-41 963:54-70 966:23-41 966:54-78
 @ ./src/app/app.module.ts 14:0-139 39:4-24 40:4-29 43:17-55
 @ ./src/main.ts 5:0-45 11:46-55

So it seems that the nativescript builder looks into ../platform/node directory instead of ../platform/browser directory. To confirm that hypothesis, in ../platform/index.js I manually changed

export * from './node';

to

export * from './browser';

in a dozen of places under node_modules/@opentelemetry folder. That let me successfully compile my mobile nativescript app.

So, to reiterate, my question is how to I tell the buider to use the .../browser directory instead of .../node directory?

I created an example project showing this issue: https://github.com/eighteight/nativescript-opentelemetry

eighteight avatar Oct 27 '22 16:10 eighteight

I'm not familiar with nativescript. From a quick peek into your example project, I found that you may using webpack to bundle your application. Please refer to webpack's documentation https://webpack.js.org/configuration/resolve/#resolvealiasfields to define your preferred package alternative fields, e.g. browser (https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-core/package.json#L8).

legendecas avatar Nov 04 '22 08:11 legendecas

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] avatar Jan 09 '23 06:01 github-actions[bot]

This issue was closed because it has been stale for 14 days with no activity.

github-actions[bot] avatar Jan 30 '23 06:01 github-actions[bot]