Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set property 'telemetry' of undefined #41

Open
1234ani opened this issue Jul 27, 2020 · 1 comment
Open

Cannot set property 'telemetry' of undefined #41

1234ani opened this issue Jul 27, 2020 · 1 comment

Comments

@1234ani
Copy link

1234ani commented Jul 27, 2020

while integarting the @project-sunbird telemetry with the angular 10 application this is the error i am facing

Error:TypeError: Cannot set property 'telemetry' of undefined

Here is the complete stacktrace of the error

index.js:1829 Uncaught TypeError: Cannot set property 'telemetry' of undefined
at index.js:1829
at Object.../../node_modules/@project-sunbird/telemetry-sdk/index.js (index.js:2393)
at webpack_require (bootstrap:84)
at Module.../../dist/infosys-telemetry-lib/fesm2015/infosys-telemetry-lib.js (infosys-telemetry-lib.js:1)
at webpack_require (bootstrap:84)
at Module../src/app/app.component.ts (app-shell.component.ts:42)
at webpack_require (bootstrap:84)
at Module../src/app/app.module.ts (app.module.ts:1)
at webpack_require (bootstrap:84)
at Module../src/main.ts (main.ts:2)

@kiranjholla
Copy link

kiranjholla commented Mar 11, 2021

So it appears to me that this is because the code within https://github.com/project-sunbird/sunbird-telemetry-sdk/blob/master/js/core/telemetryV3Interface.js#L26 assumes that it will run in a non-strict mode.

When this package is used in an environment involving bundlers or in an environment where 'use strict' is enforced, then we will see this error.

The is the code causing the problem:

var Telemetry = (function() {
  this.telemetry = function() {};
  var instance = function() {};
  var telemetryInstance = this;
  ...
  return this.telemetry;
})();

Here, the this value will be set to the global window object when running in a non-strict mode and everything works fine. But when used within a bundler or in strict mode, this is undefined and that results in this error.

You could possibly solve this by avoiding the use of this here, and simply initializing telemetry as a local variable, because the function is anyway not being used as a constructor.

var Telemetry = (function() {
  const telemetryInstance = this || {};
  const self = telemetryInstance;
  const instance = function() {};

  self.telemetry = function() {};
  self.telemetry.initialized = false;
  self.telemetry.config = {};
  self.telemetry._version = "3.0";
  self.telemetry.fingerPrintId = undefined;
  self.dispatcher = libraryDispatcher;
  ...
  return self.telemetry;
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants