Skip to content

Runtime errors after upgrading to @sentry/vite-plugin@4.0.1 #782

Description

@alSergey

Environment

  • @sentry/vite-plugin@4.0.1
  • @sentry/vue@9.44.2
  • nuxt@3.17.5
  • vite@6.3.5

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/vite-plugin@4.0.0 to @sentry/vite-plugin@4.0.1, 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/vite-plugin@4.0.1, 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/vite-plugin@4.0.0:
{
    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/vite-plugin@4.0.2, 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

Labels

No labels
No labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions