question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v 4.11.0 - Cannot read properties of undefined (reading 'INTAKE_SITE_US5')

See original GitHub issue

Of Note

This appears to be different to https://github.com/DataDog/browser-sdk/issues/1547

  • Using @datadog/browser-rum: with "react": "18.1.0" and "react-dom": "18.1.0"
  • Using @datadog/browser-rum: 4.11.0 - errors
  • Using @datadog/browser-rum: 4.9.0 - works

Versions that work

The version our code last worked with is @datadog/browser-rum 4.9.0

Version that don’t work

Using @datadog/browser-rum >= 4.10.0 we have the below problem

This issue is also present on:

  • @datadog/browser-rum 4.10.4
  • @datadog/browser-rum 4.11.0

Issue

When placing datadog.init within an if statement so it only runs in a particular environment (production):

import {datadogRum} from '@datadog/browser-rum';


  if (config.isProduction) {
      datadogRum.init({
...

And we run the code in the not allowed environment (not production), we get the error:

Uncaught TypeError: Cannot read properties of undefined (reading 'INTAKE_SITE_US5')

Note this works fine on v4.11.0 when it is in the allowed environment (production). But gives us the error when it is not in the allowed environment.

  • I have noticed if I comment out the datadogRum.init call that is inside the if that is not executed, then I do not get the error.
  • I have also sanity checked that the if condition is correct and the code does not enter the if statement, the datadogRum.init doesn’t run when you are not in the allowed environment
  • It is almost as if the If statement is not being respected and the inclusion of datadogRum.init in the code, even though it is not being ran, is causing this error.
  • If I set up a vanilla React and Datadog example with v4.11.0 inside an if that is not executed, it runs without an error - https://stackblitz.com/edit/react-ts-luwuak?file=App.tsx
  • But in our apps code (sorry I can’t share the code) if I only change "@datadog/browser-rum" from "4.9.0" to 4.11.0 it gives us the Uncaught TypeError: Cannot read properties of undefined (reading 'INTAKE_SITE_US5') error in environments where the code inside the if statement is not executed
  • Because of the previous point this feels like the package change of "@datadog/browser-rum" is causing this issue but only in our setup. I’m struggling to see what else is causing this or what is missing between v4.9.0 and v4.11.0
  • The code with v4.11.0 runs fine in the “allowed” environment (production)
  • Is this potentially a Webpack circular dependency bug?
  • Very weird issue so it feels like there is something going on that I am unaware of

Fix

My current fix is to lock @datadog/browser-rum: to v4.9.0, this works in all environments, but is not ideal

Please let me know if you need anything else that could be of help?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
BenoitZugmeyercommented, May 30, 2022

A new version have been released, but I still spoted some circular depencies! Your issue might be solved without waiting for the last circular dependencies to be fixed though. Let me know.

1reaction
BenoitZugmeyercommented, May 25, 2022

Just to keep you updated, the last circular dependencies have been removed with https://github.com/DataDog/browser-sdk/pull/1567 . We’ll release a new version on Monday if everything’s right.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError : Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Cannot read properties of undefined (reading '0') · Issue #10115
Describe the bug chunk-AGYRAQNY.js?v=5a966010:8786 Uncaught TypeError: Cannot read properties of undefined (reading '0') at useSWRHandler ...
Read more >
Getting "Cannot read properties of undefined ... - Stack Overflow
card-body · card-header · card-footer when I try to build the library, it gives a error "Cannot read properties of undefined (reading 'includes')"....
Read more >
How to Prevent the Error: Cannot Read Property '0' of Undefined
A guide on how to prevent the error "cannot Read Property '0' of Undefined", covering techniques such as try, catch, using const over...
Read more >
cannot read properties of undefined (reading 'create') node js
I am new to Vue js and faced with the following problem: When trying to launch a project, an error occurs: Cannot read...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found