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

Next.js Config as function is unsupported sometime after 7.12.1 #6447

Closed
3 tasks done
kylemh opened this issue Dec 6, 2022 · 3 comments
Closed
3 tasks done

Next.js Config as function is unsupported sometime after 7.12.1 #6447

kylemh opened this issue Dec 6, 2022 · 3 comments

Comments

@kylemh
Copy link

kylemh commented Dec 6, 2022

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.23.0

Framework Version

Next.js 12.3.4

Link to Sentry event

No response

Steps to Reproduce

  1. Open this sandbox link
  2. Run yarn build
  3. Notice that Next.js throws an error that the config is a function instead of an object. Next.js actually runs, but my entire config has been ignored.

Expected Result

When using the Sentry plugin, my original Next.js config is maintained. It's valid to use next.config.js as a function (as described here) and necessary in order to even use this plugin since it's a partial function.

Actual Result

See sandbox link in STR.

I think this is the culprit: #6291


For whatever fix gets applied here, I think it'd be ideal to include a test for a Next.js application with multiple plugins to protect against regression.

@kylemh
Copy link
Author

kylemh commented Dec 6, 2022

First noticed this when trying to upgrade from 7.12.1 --> latest (7.24.0) and all of my next config options were being ignored.

@lforst
Copy link
Member

lforst commented Dec 7, 2022

Your configuration has a bug. You need to pass in all the arguments from the export like this:

module.exports = (phase, defaultConfig) => {
  const plugins = [
    // presume I have other plugins
    (config) => withSentryConfig(config, sentryWebpackPluginOptions),
  ];

  const config = plugins.reduce(
    (acc, plugin) => {
      const pluginReturnValue = plugin(acc);

      let newConfig;
      if (typeof pluginReturnValue === "function") {
        newConfig = pluginReturnValue(phase, defaultConfig);
      } else {
        newConfig = pluginReturnValue;
      }

      console.log("This should be an object now", {
        newConfig,
      });

      return newConfig;
    },
    { ...nextConfig }
  );

  return config;
};

Let me know if this fixes the issue for you.

@kylemh
Copy link
Author

kylemh commented Dec 7, 2022

I'm confused as to what changed within @sentyr/nextjs since this code worked before. That being said, this is an easy tweak I can make so thanks for that solution. For context next-compose-plugins hasnt seen an update in a while and people gravitated towards this workaround. I'll share this fact in that thread so nobody else has an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants