microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
321 stars 138 forks source link

Angular SSR Application Insights tracking: Module 'applicationinsights' used by 'apps/dummy-app/server.ts' is not ESM #1341

Closed work933k closed 4 days ago

work933k commented 3 weeks ago

When trying to use this module in an out-of-the-box Angular SSR application, errors are given about that the module is not ESM. How can this be made to work?

▲ [WARNING] Constructing "ImportInTheMiddle" will crash at run-time because it's an import namespace object, not a constructor [call-import-namespace]

    node_modules/@azure/opentelemetry-instrumentation-azure-sdk/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js:268:24:
      268 │       var esmHook = new ImportInTheMiddle([module_2.name], {
          ╵                         ~~~~~~~~~~~~~~~~~

  Consider changing "ImportInTheMiddle" to a default import instead:

    node_modules/@azure/opentelemetry-instrumentation-azure-sdk/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js:58:7:
      58 │ import * as ImportInTheMiddle from 'import-in-the-middle';
         │        ~~~~~~~~~~~~~~~~~~~~~~
         ╵        ImportInTheMiddle

▲ [WARNING] Constructing "ImportInTheMiddle" will crash at run-time because it's an import namespace object, not a constructor [call-import-namespace]

    node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js:296:24:
      296 │       var esmHook = new ImportInTheMiddle([module_2.name], {
          ╵                         ~~~~~~~~~~~~~~~~~

  Consider changing "ImportInTheMiddle" to a default import instead:

    node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js:58:7:
      58 │ import * as ImportInTheMiddle from 'import-in-the-middle';
         │        ~~~~~~~~~~~~~~~~~~~~~~
         ╵        ImportInTheMiddle

▲ [WARNING] Module 'applicationinsights' used by 'apps/platform-app/server.ts' is not ESM

  CommonJS or AMD dependencies can cause optimization bailouts.
  For more information see: https://angular.io/guide/build#configuring-commonjs-dependencies
JacksonWeber commented 2 weeks ago

@work933k I expect this issue to be resolved by https://github.com/open-telemetry/opentelemetry-js/pull/4745 as other OpenTelemetry users were experiencing the same issue documented here in this issue: https://github.com/open-telemetry/opentelemetry-js/issues/4717 which is marked as resolved by that PR. Since the fix was released in v0.52.0 of the experimental package which we're updating to in the Azure Monitor OpenTelemetry release today, this fix will be available upon the next release of this package.

work933k commented 4 days ago

By overriding a dependency, the error seems to be resolved.

...
  "overrides": {
    "@opentelemetry/instrumentation": "0.52.1"
  },
...