Next.js SDK incompatibility with bundle analyzer
See original GitHub issueIs there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
SDK Version
7.22.0
Framework Version
13.0.5
Link to Sentry event
No response
Steps to Reproduce
After upgrading @sentry/nextjs from 7.21.1 to 7.22.0, the environment variables in next.config.js get dropped and can no longer be accessed from next app.
// next.config.js
const { withSentryConfig } = require("@sentry/nextjs");
const withBundleAnalyzer = require("@next/bundle-analyzer")({ enabled: process.env.ANALYZE === "true" });
const moduleExports = { env: { myConfig: 'MY_CONFIG' }, ... }
const SentryWebpackPluginOptions = { silent: true };
module.exports = withBundleAnalyzer(withSentryConfig(moduleExports, SentryWebpackPluginOptions));
The config code above worked fine before 7.22.0. At 7.22.0 it would work if withBundleAnalyzer is removed though.
Expected Result
In next app console.log(process.env.myConfig) should print MY_CONFIG on browser.
Actual Result
console.log(process.env.myConfig) prints undefined
Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:10 (5 by maintainers)
The method signature of
withSentryConfig
always returned a function or an object: https://github.com/getsentry/sentry-javascript/blob/2ed5f8f922c831b58a5b2d24edfeb655f3cd0b9c/packages/nextjs/src/config/withSentryConfig.ts#L20It’s just that with the recent version it now always returns a function - which is non-breaking type-signature-wise.
Next.js allows you to export a function in your config: https://nextjs.org/docs/api-reference/next.config.js/introduction#:~:text=You can also use a function
Some libraries don’t seem to honor that though.
Another thing: We generally advise to wrap your config with
withSentryConfig
last.