microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

work933k opened this issue · comments

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

@work933k I expect this issue to be resolved by open-telemetry/opentelemetry-js#4745 as other OpenTelemetry users were experiencing the same issue documented here in this issue: open-telemetry/opentelemetry-js#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.

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

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