0

I have the following implementation in the app.module.ts

export class AppModule {
  
  constructor(@Inject(ApmService) service: ApmService) {
    setTimeout(()=> { 
     const apm = service.init({
      active: environment.elasticApmActive,
      environment: environment.production ? 'prod' : 'qa',
      serviceName: environment.appName,
      serverUrl: environment.elasticServerUrl
    });
    }, 1000) 
  }
}

And whenever my angular 13 application gets loaded, it shows me below error enter image description here

My tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "",
    "declaration": false,
    "downlevelIteration": true,
    "skipLibCheck": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom", "es2017", "es2019"],
    "mapRoot": "./",
    "module": "es2020",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es2015",
    "strictPropertyInitialization": false,
    "typeRoots": [
        "../node_modules/@types"
    ],
    "types": ["jasmine"],
    "paths": {
      "crypto": ["../node_modules/crypto-browserify","../node_modules/crypto-js"],
      "stream": ["../node_modules/readable-stream"],
      "zlib": ["../node_modules/browserify-zlib"],
      "http": ["../node_modules/stream-http"],
      "https": ["../node_modules/https-browserify"],
      "assert": ["../node_modules/assert"],
      "util": ["../node_modules/util"]
    }
  },
  "files": [
    "main.ts",
    "polyfills.ts"
  ],
  "include": [
    "../node_modules/@careem/angular-react-adapter/src/ReactDirective.ts",
  ],
}

I have tried to change target:"es5" but still gives me the same error. Please help me try to find a solution to this.

Maliha Khizer
  • 117
  • 1
  • 11
  • Why do you set the time out in the constructor ? – onrails Jul 13 '22 at 15:51
  • It is probably caused by the `setTimeOut()` method you wrap your async function in it. `NgZone` will not be able to catch the `async` change that I assume is represented by `service.init(...)` in the code above. Try to remove the `SetTimeOut` and use another technique such as `async/await` or another lifecycle-hook such as `AfterViewInit`. If you still have an issue please paste a link into a complete stackblitz. – onrails Jul 13 '22 at 15:56

0 Answers0