Cannot read property 'LEENDPOINT' of undefined

326 Views Asked by At

I am integrating LogEntries in my react application.

But right after importing LogEntry js file. I am getting console error that:

const Logger = require ('./logger.jsx')('your token', {trace: true});

Error:

le.min.js:5 Uncaught TypeError: Cannot read property 'LEENDPOINT' of undefined
at new e (le.min.js:5)
at new p (le.min.js:10)
at f (le.min.js:11)
at Object.init (le.min.js:12)
at module.exports (logger.jsx:9)
at Object.defineProperty.value (App.js:10)
at __webpack_require__ (bootstrap 9c287bdecc8b4481a87b:19)
at Object.defineProperty.value (AppWrapper.js:2)
at __webpack_require__ (bootstrap 9c287bdecc8b4481a87b:19)
at Object.<anonymous> (index.js:8)

Update:

After debbuging I came to know that window object is undefined in logger file. This is piece of code which is causing havoc:

     if (window.LEENDPOINT) {
        _endpoint = window.LEENDPOINT;
    }

Still looking for solution.

Update 2.0:

Here is my Logger.jsx

const LogEntries = require ('./le.min.js');

module.exports =  (token, opts={}) => {
if(!token){
    throw new Error ('A valid token is required for all LogEntries library implementations.');
}

opts.token = token;
LogEntries.init(opts);
return LogEntries;
}
1

There are 1 best solutions below

0
Rahul On

Following solution worked for me:

  1. Downloaded le.min.js from https://docs.logentries.com/docs/javascript
  2. Imported <script src="/assets/scripts/le.min.js"></script> in my index.html. Make sure you import it before bundle.js
  3. Created one file. Logger.js

    const token = 'token';

    const region = 'us';

    const trace = true;

    /*eslint-disable */

    LE.init({ token, region, trace});

    export default LE;

    /*eslint-enable */

  4. Whenever you want to make log import import Logger from './Logger';

  5. Log using: Logger.error('Log');