Skip to content
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

fix: handle process.version set to undefined #78

Merged
merged 3 commits into from
Sep 18, 2023

Conversation

jaschaephraim
Copy link
Contributor

@jaschaephraim jaschaephraim commented Sep 15, 2023

Resolves #77
Related vercel/next.js#54739

The Edge Runtime is not Node.js, but will have a global process defined. Most properties of process will be present but undefined, so "version" in process will be true. This will currently lead to a false identification as Node.js, and an error when calling process.version.substr(1). This PR instead checks that process.version !== undefined.

It also will check if typeof EdgeRuntime === "string", which is how the Edge environment is checked in Vercel, and then return user agent "Edge Runtime" (which is not standard in any way, but possibly better than nothing). When a request is actually sent from a Vercel Edge function it has the user agent "Next.js Middleware", but I don't see anyway to detect that specifically.

Let me know if you'd like me to remove this detection of the Edge Runtime and just fall back to <environment undetectable>.

index.js Outdated
Comment on lines 12 to 14
if (typeof EdgeRuntime === "string") {
return "Edge Runtime";
}
Copy link
Owner

Choose a reason for hiding this comment

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

I don't feel too comfortable to start adding vendor-specific code. Could you for now leave that out and we discuss it in an issue? Maybe we can find another way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For sure, removed

@gr2m gr2m changed the title Support Edge Runtime fix: handle process.version set to undefined Sep 18, 2023
@gr2m gr2m merged commit 5a47b86 into gr2m:master Sep 18, 2023
@github-actions
Copy link

🎉 This PR is included in version 7.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

gr2m pushed a commit that referenced this pull request Nov 4, 2023
Vercel's [Edge Runtime](https://edge-runtime.vercel.app/) is not Node.js, but will have a global `process` defined
gr2m added a commit that referenced this pull request Nov 4, 2023
Vercel's [Edge Runtime](https://edge-runtime.vercel.app/) is not Node.js, but will have a global `process` defined

Co-authored-by: Jascha Ephraim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Universal user agent not working in next.js edge runtime
2 participants