Skip to content

fix(nextjs): Don't crash build when auth token is missing #7427

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

Merged
Merged
Changes from 1 commit
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
33 changes: 32 additions & 1 deletion packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,38 @@ export function getWebpackPluginOptions(

checkWebpackPluginOverrides(defaultPluginOptions, userPluginOptions);

return { ...defaultPluginOptions, ...userPluginOptions };
return {
...defaultPluginOptions,
...userPluginOptions,
errorHandler(err, invokeErr, compilation) {
// Hardcoded way to check for missing auth token until we have a better way of doing this.
if (err && err.message.includes('Authentication credentials were not provided.')) {
const warningPrefix = `${chalk.yellow('warn')} -`;
// eslint-disable-next-line no-console
console.warn(
`${warningPrefix} ${
`${chalk.bold('No Sentry auth token configured.')} Source maps will not be uploaded.\n` +
'You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/\n' +
`After generating a Sentry auth token, set it via the ${chalk.bold.cyan(
'SENTRY_AUTH_TOKEN',
)} environment variable during the build.\n`
}${
process.env.VERCEL
? "If you're deploying to Vercel, use the Vercel integration: https://vercel.com/integrations/sentry\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
? "If you're deploying to Vercel, use the Vercel integration: https://vercel.com/integrations/sentry\n"
? "If you're deploying to Vercel, use the Vercel integration to automatically set a Sentry auth token: https://vercel.com/integrations/sentry\n"

Should we even show the above lines if we are on Vercel? It should be enough to just say, hey set the Vercel integration, thats all you need to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion: c86e63c Thanks!

: ''
}`,
);

return;
}

if (userPluginOptions.errorHandler) {
return userPluginOptions.errorHandler(err, invokeErr, compilation);
}

return invokeErr();
},
};
}

/** Check various conditions to decide if we should run the plugin */
Expand Down