Open arranf opened 2 weeks ago
It's unfortunate that fallbackNodePolyfills
also removes process.env
, because at built-time webpack should just replace process.env.X
with the according values (with EnvironmentPlugin
). As such there should be no extra bundle size hit from any process.env
logic.
I guess we should also support this use case given it makes sense to not use these APIs on the browser. Going to backlog, but PRs are welcome!
ref: https://nextjs.org/docs/pages/api-reference/next-config-js/env
Considering these are in the official Next.js docs, I'm even more hesitant in assuming any defaults where process.env
does not exist. We'll be relying on this more as well as turbopack gets more mature: https://github.com/getsentry/sentry-javascript/pull/14081
ref: https://nextjs.org/docs/pages/api-reference/next-config-js/env
Considering these are in the official Next.js docs, I'm even more hesitant in assuming any defaults where
process.env
does not exist. We'll be relying on this more as well as turbopack gets more mature: #14081
@AbhiPrasad I agree this is odd! In the project I discovered this on this option is set however when the polyfills option is turned off, these variables are not set for the client. I wonder if this is intended behaviour?
Just so that we're aligned... you mean that if you set fallbackNodePolyfills: false
, the application crashes right? Cause in your report you're saying that we are crashing when the option is not set - which would really surprise me.
I looked a bit in the Next.js code base and I think what's happening here is that the Vercel folks may have forgotten that process.env
is used with a lot of other features of the framework and it will simply break?
I honestly don't think we will work around this experimental option for now. I recommend turning it off. If it ends up becoming stable we will of course find a solution.
Just so that we're aligned... you mean that if you set
fallbackNodePolyfills: false
, the application crashes right? Cause in your report you're saying that we are crashing when the option is not set - which would really surprise me.I looked a bit in the Next.js code base and I think what's happening here is that the Vercel folks may have forgotten that
process.env
is used with a lot of other features of the framework and it will simply break?I honestly don't think we will work around this experimental option for now. I recommend turning it off. If it ends up becoming stable we will of course find a solution.
Sorry - yes, you're absolutely right. It fails when set to false. My fault for writing up a bug report at 2am after figuring this out!
That's fair enough - I do think you guys are right this should probably be an upstream change. I'll report this to Vercel.
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
8.37.1
Framework Version
Next 15.0.2
Link to Sentry event
No response
Reproduction Example/SDK Setup
Steps to Reproduce
next dev
with the config aboveTypeError: process.env is undefined
fallbackNodePolyfills
next dev
Expected Result
process.env
Actual Result
node_modules/@sentry/nextjs/build/cjs/client/index.js
'sinit
function has multiple calls toprocess.env
and assumes a polyfill.