Skip to content

Runtime errors after upgrading to @sentry/[email protected]Β #782

@alSergey

Description

@alSergey

Environment

Steps to Reproduce

It's quite difficult to describe the steps to reproduce because the issue doesn't occur across all projects. I'll try to explain what I discovered.

I'm using Nuxt with the Vite bundler. After upgrading from @sentry/[email protected] to @sentry/[email protected], I started encountering a runtime error when launching the service:

ReferenceError: Cannot access 'k' before initialization
Image

When I checked the line where the code fails, I saw the following:

(function() {
    var e = typeof k < "u" ? k : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {}; // The error occurs on this line
    e.SENTRY_RELEASE = {
        id: "first-project"
    }
}
)();

For unclear reasons, the variable k appears in the code, even though when checking your source code, it's explicitly written as window, and there's no mention of k. As far as I understand, this code is further processed by Vite, and for some reason, window is being replaced with k.

Interestingly, in another Nuxt project where I'm also using @sentry/[email protected], everything works correctly. There are no significant differences between the two projects. Here's an example of the working code:

(function() {
    var e = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {};
    e.SENTRY_RELEASE = {
        id: "second-project"
    }
}
)();

Additional information

  1. Here’s an example from the first project using @sentry/[email protected]:
{
    let e = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {};
    e.SENTRY_RELEASE = {
        id: "first-project"
    }
}
  1. I also tried upgrading to @sentry/[email protected], and the issue persists.

  2. If you run the erroneous code in the console, there is no error and everything works correctly:

Image

Expected Result

No runtime errors

Actual Result

Runtime errors occur

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions