question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Next.js SDK incompatibility with bundle analyzer

See original GitHub issue

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

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:closed
  • Created 10 months ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lforstcommented, Dec 1, 2022

This looks like a breaking change though since the same setup (working from 7.15.0) is now throwing errors / causing issues.

Having the same issue with next-i18next which does not have any next.config plugin. I disabled all plugins and they all work as usual except for sentry. It definitely looks like your changes were not versioned correctly (investigating)

EDIT

Moving sentry to the end of the config chain helped in my case, but I’m wondering if such a restriction should even be required.

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#L20

It’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.

1reaction
lforstcommented, Nov 30, 2022

Another thing: We generally advise to wrap your config with withSentryConfig last.

Read more comments on GitHub >

github_iconTop Results From Across the Web

josselinbuils/next-bundle-analyzer: NextJS version of ... - GitHub
Webpack Bundle Analyzer is a great tool to analyze the bundles of web applications built on top of Webpack but trying to use...
Read more >
Advanced Features: Next.js Compiler
The Next.js Compiler, written in Rust using SWC, allows Next.js to transform and minify your JavaScript code for production. This replaces Babel for...
Read more >
@next/bundle-analyzer - npm
Next.js + Webpack Bundle Analyzer. Use webpack-bundle-analyzer in your Next.js project. Installation. npm install @next/bundle-analyzer.
Read more >
Configure multiple next plugins: withMDX, withBundleAnalyzer
I am now trying to get .mdx files to work from the pages directly. Documentation says I need withMDX in my nextjs.config file....
Read more >
NextJS Bundle Optimization to improve Performance
Install @next/bundle-analyzer library to analyze the build of the application. Through the Bundle analyzer, we will understand the library sizes ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found