Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 11 additions & 55 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({

const { i18n } = require("./next-i18next.config");

// Use the SentryWebpack plugin to upload the source maps during build step
const SentryWebpackPlugin = require("@sentry/webpack-plugin");
const { withSentryConfig } = require("@sentry/nextjs");

const {
NEXT_PUBLIC_SENTRY_DSN: SENTRY_DSN,
SENTRY_ORG,
SENTRY_PROJECT,
SENTRY_AUTH_TOKEN,
NODE_ENV,
VERCEL_GIT_COMMIT_SHA,
VERCEL_GITHUB_COMMIT_SHA,
VERCEL_GITLAB_COMMIT_SHA,
Expand All @@ -28,7 +25,14 @@ const COMMIT_SHA =
VERCEL_BITBUCKET_COMMIT_SHA ||
SOURCE_VERSION;

process.env.SENTRY_DSN = SENTRY_DSN;
const sentryWebpackPluginOptions = {
silent: false,
authToken: SENTRY_AUTH_TOKEN,
org: SENTRY_ORG,
project: SENTRY_PROJECT,
release: COMMIT_SHA,
};

const basePath = "";

const scheme =
Expand All @@ -55,54 +59,6 @@ const nextConfig = {
serverRuntimeConfig: {
rootDir: __dirname,
},
webpack: (config, options) => {
// In `pages/_app.js`, Sentry is imported from @sentry/browser. While
// @sentry/node will run in a Node.js environment. @sentry/node will use
// Node.js-only APIs to catch even more unhandled exceptions.
//
// This works well when Next.js is SSRing your page on a server with
// Node.js, but it is not what we want when your client-side bundle is being
// executed by a browser.
//
// Luckily, Next.js will call this webpack function twice, once for the
// server and once for the client. Read more:
// https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config
//
// So ask Webpack to replace @sentry/node imports with @sentry/browser when
// building the browser's bundle
if (!options.isServer) {
config.resolve.alias["@sentry/node"] = "@sentry/browser";
}

// config.node = {
// fs: 'empty',
// };

// When all the Sentry configuration env variables are available/configured
// The Sentry webpack plugin gets pushed to the webpack plugins to build
// and upload the source maps to sentry.
// This is an alternative to manually uploading the source maps
// Note: This is disabled in development mode.
if (
SENTRY_DSN &&
SENTRY_ORG &&
SENTRY_PROJECT &&
SENTRY_AUTH_TOKEN &&
COMMIT_SHA &&
NODE_ENV === "production"
) {
config.plugins.push(
new SentryWebpackPlugin({
include: ".next",
ignore: ["node_modules"],
stripPrefix: ["webpack://_N_E/"],
urlPrefix: `~${basePath}/_next`,
release: COMMIT_SHA,
})
);
}
return config;
},
basePath,
// your config for other plugins or the general next.js here...
env: {
Expand Down Expand Up @@ -143,7 +99,7 @@ const nextConfig = {
},
};

module.exports = () => {
module.exports = withSentryConfig(() => {
const plugins = [withBundleAnalyzer];
return plugins.reduce((config, plugin) => plugin(config), nextConfig);
};
}, sentryWebpackPluginOptions);
Loading