Sentry-javascript: ReferenceError: document is not defined

Created on 19 Jan 2021  路  4Comments  路  Source: getsentry/sentry-javascript

Package + Version

  • [ ] @sentry/browser
  • [ ] @sentry/node
  • [ ] raven-js
  • [ ] raven-node _(raven for node)_
  • [x] other: @sentry/react

Version:

6.0.0

Description

I am using Sentry with my Next.js project, I am using static export feature of the Next.js. Today I updated @sentry/react package from version 5.24.2 to 6.0.0. I get ReferenceError: document is not defined both on development mode and when building.

The only Sentry-related code in my project is this:

import * as Sentry from '@sentry/react';

Sentry.init({
  dsn: process.env.NEXT_PUBLIC_PROJECT_SENTRY_WEB_APP_DSN,
  environment: process.env.NEXT_PUBLIC_PROJECT_STAGE,
});

The full trace is like this:

ReferenceError: document is not defined
    at startSessionTracking (/Users/th0th/Workspace/project/project-frontend/node_modules/@sentry/browser/dist/sdk.js:196:24)
    at Object.init (/Users/th0th/Workspace/project/project-frontend/node_modules/@sentry/browser/dist/sdk.js:101:9)
    at Object.init (/Users/th0th/Workspace/project/project-frontend/node_modules/@sentry/react/dist/sdk.js:18:15)
    at eval (webpack-internal:///./pages/_app.tsx:66:51)
    at Module../pages/_app.tsx (/Users/th0th/Workspace/project/project-frontend/packages/web-app/.next/server/pages/_app.js:3324:1)
    at __webpack_require__ (/Users/th0th/Workspace/project/project-frontend/packages/web-app/.next/server/pages/_app.js:23:31)
    at Object.0 (/Users/th0th/Workspace/project/project-frontend/packages/web-app/.next/server/pages/_app.js:3335:18)
    at __webpack_require__ (/Users/th0th/Workspace/project/project-frontend/packages/web-app/.next/server/pages/_app.js:23:31)
    at /Users/th0th/Workspace/project/project-frontend/packages/web-app/.next/server/pages/_app.js:91:18
    at Object.<anonymous> (/Users/th0th/Workspace/project/project-frontend/packages/web-app/.next/server/pages/_app.js:94:10)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at requirePage (/Users/th0th/Workspace/project/project-frontend/node_modules/next/dist/next-server/server/require.js:1:1184)
    at loadComponents (/Users/th0th/Workspace/project/project-frontend/node_modules/next/dist/next-server/server/load-components.js:1:865)
    at DevServer.findPageComponents (/Users/th0th/Workspace/project/project-frontend/node_modules/next/dist/next-server/server/next-server.js:74:296)
    at DevServer.renderToHTML (/Users/th0th/Workspace/project/project-frontend/node_modules/next/dist/next-server/server/next-server.js:133:465)
    at DevServer.renderToHTML (/Users/th0th/Workspace/project/project-frontend/node_modules/next/dist/server/next-dev-server.js:34:590)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async DevServer.render (/Users/th0th/Workspace/project/project-frontend/node_modules/next/dist/next-server/server/next-server.js:72:236)
    at async Object.fn (/Users/th0th/Workspace/project/project-frontend/node_modules/next/dist/next-server/server/next-server.js:56:580)
    at async Router.execute (/Users/th0th/Workspace/project/project-frontend/node_modules/next/dist/next-server/server/router.js:23:67)
    at async DevServer.run (/Users/th0th/Workspace/project/project-frontend/node_modules/next/dist/next-server/server/next-server.js:66:1042)
    at async DevServer.handleRequest (/Users/th0th/Workspace/project/project-frontend/node_modules/next/dist/next-server/server/next-server.js:34:1081)
Needs Triage

Most helpful comment

The patch is on its way. Sorry for the inconvenience.

All 4 comments

I came here looking for help with this same issue.

Setting autoSessionTracking: false, in Sentry.init() seems to at least make the app work until we get a fix.

We have the same issue with Sentry 6.0.1 and @sentry/angular when using SSR. We reverted back to 5.30.0 for the time being.

The patch is on its way. Sorry for the inconvenience.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kamilogorek picture kamilogorek  路  3Comments

adepue picture adepue  路  3Comments

THPubs picture THPubs  路  3Comments

simllll picture simllll  路  3Comments

grigored picture grigored  路  3Comments