I recently updated Next.js to version 12.2.3 and I found out that next-compose-plugins do not work anymore. After peek at GitHub issue and I was able to copy and paste working solution:
/**
* @type {import('next').NextConfig}
*/
module.exports = () => {
const plugins = [withTM, withVanillaExtract, withSentryConfig];
return plugins.reduce((acc, next) => next(acc), {
i18n: {
locales: ["en-US", "nl-BE", "pl-PL"],
defaultLocale: "en-US",
},
});
};
It worked fine but I wanted to pass argument to withSentryConfig - i turns out that I need to pass it as another argument to next function in reduce:
return plugins.reduce((acc, next) => {
if (next.name === 'withSentryConfig') {
return next(acc, {silent: true });
}
return next(acc);
}, {
// the rest of next.js config
});
Changelog
- Update the last snippet after feedback from Miguel Leite
Top comments (5)
You need to be careful about the final
reduce, since you're passing thesilentproperty to every single plugin. You're also missing a closing parenthesis on thenext()call.How about this? 👆
@miguelacleite thanks for catching that - I'll update the code 🙇🏻
Please have a look at the successor of
next-compose-pluginswhich is next-recompose-plugins. This package provides a clean and easy API for Next.js's plugins configuration and composition.Here is a sneak peek:
I highly recommend this package because it allows us to apply plugins seamlessly, the plugin application is less error prone, and the final code looks clean and consistent.
Hello, I would like to ask a question, in next.js, how to execute the init() of sentry only on the client side, not on the server side, because window is not defined
import { init, WINDOW } from "@sentry/nextjs";