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.

TypeError: Cannot read properties of undefined (reading 'getElementById')

See original GitHub issue

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.12.0

Framework Version

"next": "12.2.5"

Link to Sentry event

No response

Steps to Reproduce

  1. Install Next.JS
  2. Use next js edge functions
  3. See sentry error on server

Expected Result

Zero errors

Actual Result

TypeError: Cannot read properties of undefined (reading 'getElementById')
    at node_modules/@sentry/nextjs/esm/performance/client.js:22:26
    at node_modules/@sentry/nextjs/esm/performance/client.js:94:54
    at node_modules/@sentry/tracing/esm/browser/browsertracing.js:99:0
    at node_modules/@sentry/core/esm/integration.js:64:0
    at <anonymous>
    at node_modules/@sentry/core/esm/integration.js:60:0
    at node_modules/@sentry/core/esm/baseclient.js:217:27
    at node_modules/@sentry/hub/esm/hub.js:65:0
    at node_modules/@sentry/core/esm/sdk.js:32:0
    at node_modules/@sentry/browser/esm/sdk.js:110:2
    at node_modules/@sentry/react/esm/sdk.js:18:2
    at node_modules/@sentry/nextjs/esm/index.client.js:31:2
    at sentry.server.config.ts:8:0
    at webpack/bootstrap:21:0
    at node_modules/react/index.js:4:2
    at node_modules/react/index.js:4:2
    at webpack/runtime/jsonp chunk loading:34:0
    at api/github:middleware.js:1:17

Link to CODE

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
wconnorwalshcommented, Sep 22, 2022

I had the same issue: sentry.client.config.js and/or sentry.server.config.js erroneously bundling with experimental-edge functions.

The root cause is obviously #5611 – and I am not familiar with the internals of the withSentryConfig Next.js webpack plugin – but is it possible that it is bundling the Sentry code in every API handler, even if it is marked as experimental-edge?

Here is a temporary workaround for anyone else stuck. This will exclude the Sentry code in any edge functions.

// next.config.js

const config = {
 webpack: (config, options) => {
    if (options.isServer && options.nextRuntime === 'edge') {
      config.resolve.alias = {
        ...config.resolve.alias,
        './sentry.client.config.js': false,
        './sentry.server.config.js': false,
      }
    }
    return config
  }
}

module.exports = withSentryConfig(config)
2reactions
lobsterkatiecommented, Nov 17, 2022

I know sentry, doesn’t “have the best support for Vercel’s Edge Runtime” #5667 (comment), but there should be at least a way to ignore it for now.

Ask and you shall receive, @l1qu1d. 🙂 It happens I just merged this today: https://github.com/getsentry/sentry-javascript/pull/6207.

I’m going to close this for now, but if y’all are still having issues once that PR is released (in 7.20), please let us know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read properties of undefined ...
Only the document object offers the function getElementById. id must be unique and therefore there is no need for a HTMLElement version of ......
Read more >
Uncaught TypeError: Cannot read property of undefined In
Uncaught TypeError: Cannot read property of undefined error occurs in Chrome when you read a property or call a method on an undefined...
Read more >
Uncaught TypeError: Cannot read property of null - iDiallo
You are accessing a property of an object that is null. For example, document.getElementById('stuff') returns null. So adding .value will cause ...
Read more >
TypeError: Cannot read property 'value' of Null in JS
To solve the "Cannot read property 'value' of null" error, make sure that the JS script tag is placed at the bottom of...
Read more >
[SOLVED] Cannot Read Property 'addEventListener' of Null in ...
When a method like getElementById() or querySelector() method is used to search for an element that doesn't exist in the DOM, it returns...
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