Skip to content

fix(nextjs): Silence warning about usage of process in runtimes where it is not available #9394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 27, 2023

Conversation

lforst
Copy link
Contributor

@lforst lforst commented Oct 27, 2023

The isBrowser function is not used anywhere but accesses process and makes Next.js print a warning since process is not available in the Edge runtime.

This PR deprecates the function (because it is unused) and uses global.process instead which seems to outsmart Next.js' static code analyzer.

Also added tests to prevent stuff like this in the future: #9382

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isBrowser is used in Replay:

if (this._isInitialized && isBrowser()) {
throw new Error('Multiple Sentry Session Replay instances are not supported');
}

Do you see another way how we could keep such a check but avoid accessing process or other APIs? I'm not totally opposed to deprecating/eventually removing this function but I can see such a check being useful for full stack/SSR frameworks or stuff like electron/cordova/capacitor...

@lforst
Copy link
Contributor Author

lforst commented Oct 27, 2023

isBrowser is used in Replay

@Lms24 Dang how could I miss that... I guess I'll undeprecate it? The GLOBAL_OBJ thing still works in the case of Next.js.

@lforst lforst merged commit 3545fd5 into develop Oct 27, 2023
@lforst lforst deleted the lforst-fix-nextjs-process-usage-warning branch October 27, 2023 14:25
@mydea mydea mentioned this pull request Jan 4, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants