Skip to content

Commit ebcbdda

Browse files
author
Luca Forstner
committed
fix(nextjs): Don't crash build when auth token is missing
1 parent 63ef40e commit ebcbdda

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,38 @@ export function getWebpackPluginOptions(
626626

627627
checkWebpackPluginOverrides(defaultPluginOptions, userPluginOptions);
628628

629-
return { ...defaultPluginOptions, ...userPluginOptions };
629+
return {
630+
...defaultPluginOptions,
631+
...userPluginOptions,
632+
errorHandler(err, invokeErr, compilation) {
633+
// Hardcoded way to check for missing auth token until we have a better way of doing this.
634+
if (err && err.message.includes('Authentication credentials were not provided.')) {
635+
const warningPrefix = `${chalk.yellow('warn')} -`;
636+
// eslint-disable-next-line no-console
637+
console.warn(
638+
`${warningPrefix} ${
639+
`${chalk.bold('No Sentry auth token configured.')} Source maps will not be uploaded.\n` +
640+
'You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/\n' +
641+
`After generating a Sentry auth token, set it via the ${chalk.bold.cyan(
642+
'SENTRY_AUTH_TOKEN',
643+
)} environment variable during the build.\n`
644+
}${
645+
process.env.VERCEL
646+
? "If you're deploying to Vercel, use the Vercel integration: https://vercel.com/integrations/sentry\n"
647+
: ''
648+
}`,
649+
);
650+
651+
return;
652+
}
653+
654+
if (userPluginOptions.errorHandler) {
655+
return userPluginOptions.errorHandler(err, invokeErr, compilation);
656+
}
657+
658+
return invokeErr();
659+
},
660+
};
630661
}
631662

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

0 commit comments

Comments
 (0)