-
Notifications
You must be signed in to change notification settings - Fork 50
Description
Environment
@sentry/[email protected]
@sentry/[email protected]
[email protected]
[email protected]
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
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
- 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"
}
}
-
I also tried upgrading to
@sentry/[email protected]
, and the issue persists. -
If you run the erroneous code in the console, there is no error and everything works correctly:

Expected Result
No runtime errors
Actual Result
Runtime errors occur
Metadata
Metadata
Assignees
Labels
Projects
Status