Skip to content

Commit 027ab90

Browse files
authored
fix(nextjs): Remove usage of chalk to avoid runtime errors (#18010)
This is currently a bandaid fix to remove the `chalk` import statements that break turbopack apps during runtime until we have more details how this code gets bundled into production. ref #17806 closes #17691
1 parent 43b383c commit 027ab90

File tree

4 files changed

+14
-33
lines changed

4 files changed

+14
-33
lines changed

packages/nextjs/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
"@sentry/react": "10.21.0",
8888
"@sentry/vercel-edge": "10.21.0",
8989
"@sentry/webpack-plugin": "^4.3.0",
90-
"chalk": "3.0.0",
9190
"resolve": "1.22.8",
9291
"rollup": "^4.35.0",
9392
"stacktrace-parser": "^0.1.10"

packages/nextjs/src/config/loaders/wrappingLoader.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import commonjs from '@rollup/plugin-commonjs';
22
import { stringMatchesSomePattern } from '@sentry/core';
3-
import * as chalk from 'chalk';
43
import * as fs from 'fs';
54
import * as path from 'path';
65
import type { RollupBuild, RollupError } from 'rollup';
@@ -165,9 +164,7 @@ export default function wrappingLoader(
165164
if (!showedMissingAsyncStorageModuleWarning) {
166165
// eslint-disable-next-line no-console
167166
console.warn(
168-
`${chalk.yellow('warn')} - The Sentry SDK could not access the ${chalk.bold.cyan(
169-
'RequestAsyncStorage',
170-
)} module. Certain features may not work. There is nothing you can do to fix this yourself, but future SDK updates may resolve this.\n`,
167+
"[@sentry/nextjs] The Sentry SDK could not access the 'RequestAsyncStorage' module. Certain features may not work. There is nothing you can do to fix this yourself, but future SDK updates may resolve this.",
171168
);
172169
showedMissingAsyncStorageModuleWarning = true;
173170
}

packages/nextjs/src/config/webpack.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/* eslint-disable max-lines */
33

44
import { debug, escapeStringForRegex, loadModule, parseSemver } from '@sentry/core';
5-
import * as chalk from 'chalk';
65
import * as fs from 'fs';
76
import * as path from 'path';
87
import { sync as resolveSync } from 'resolve';
@@ -245,11 +244,7 @@ export function constructWebpackConfigFunction({
245244
vercelCronsConfig = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'vercel.json'), 'utf8')).crons;
246245
if (vercelCronsConfig) {
247246
debug.log(
248-
`${chalk.cyan(
249-
'info',
250-
)} - Creating Sentry cron monitors for your Vercel Cron Jobs. You can disable this feature by setting the ${chalk.bold.cyan(
251-
'automaticVercelMonitors',
252-
)} option to false in you Next.js config.`,
247+
"[@sentry/nextjs] Creating Sentry cron monitors for your Vercel Cron Jobs. You can disable this feature by setting the 'automaticVercelMonitors' option to false in you Next.js config.",
253248
);
254249
}
255250
}
@@ -259,9 +254,7 @@ export function constructWebpackConfigFunction({
259254
} else {
260255
// log but noop
261256
debug.error(
262-
`${chalk.red(
263-
'error',
264-
)} - Sentry failed to read vercel.json for automatic cron job monitoring instrumentation`,
257+
'[@sentry/nextjs] Failed to read vercel.json for automatic cron job monitoring instrumentation',
265258
e,
266259
);
267260
}
@@ -344,11 +337,7 @@ export function constructWebpackConfigFunction({
344337
) {
345338
// eslint-disable-next-line no-console
346339
console.log(
347-
`${chalk.yellow(
348-
'warn',
349-
)} - It seems like you don't have a global error handler set up. It is recommended that you add a ${chalk.cyan(
350-
'global-error.js',
351-
)} file with Sentry instrumentation so that React rendering errors are reported to Sentry. Read more: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#react-render-errors-in-app-router (you can suppress this warning by setting SENTRY_SUPPRESS_GLOBAL_ERROR_HANDLER_FILE_WARNING=1 as environment variable)`,
340+
"[@sentry/nextjs] It seems like you don't have a global error handler set up. It is recommended that you add a 'global-error.js' file with Sentry instrumentation so that React rendering errors are reported to Sentry. Read more: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#react-render-errors-in-app-router (you can suppress this warning by setting SENTRY_SUPPRESS_GLOBAL_ERROR_HANDLER_FILE_WARNING=1 as environment variable)",
352341
);
353342
showedMissingGlobalErrorWarningMsg = true;
354343
}
@@ -541,9 +530,7 @@ function warnAboutMissingOnRequestErrorHandler(instrumentationFile: string | nul
541530
if (!process.env.SENTRY_SUPPRESS_INSTRUMENTATION_FILE_WARNING) {
542531
// eslint-disable-next-line no-console
543532
console.warn(
544-
chalk.yellow(
545-
'[@sentry/nextjs] Could not find a Next.js instrumentation file. This indicates an incomplete configuration of the Sentry SDK. An instrumentation file is required for the Sentry SDK to be initialized on the server: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#create-initialization-config-files (you can suppress this warning by setting SENTRY_SUPPRESS_INSTRUMENTATION_FILE_WARNING=1 as environment variable)',
546-
),
533+
'[@sentry/nextjs] Could not find a Next.js instrumentation file. This indicates an incomplete configuration of the Sentry SDK. An instrumentation file is required for the Sentry SDK to be initialized on the server: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#create-initialization-config-files (you can suppress this warning by setting SENTRY_SUPPRESS_INSTRUMENTATION_FILE_WARNING=1 as environment variable)',
547534
);
548535
}
549536
return;
@@ -552,9 +539,7 @@ function warnAboutMissingOnRequestErrorHandler(instrumentationFile: string | nul
552539
if (!instrumentationFile.includes('onRequestError')) {
553540
// eslint-disable-next-line no-console
554541
console.warn(
555-
chalk.yellow(
556-
'[@sentry/nextjs] Could not find `onRequestError` hook in instrumentation file. This indicates outdated configuration of the Sentry SDK. Use `Sentry.captureRequestError` to instrument the `onRequestError` hook: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#errors-from-nested-react-server-components',
557-
),
542+
'[@sentry/nextjs] Could not find `onRequestError` hook in instrumentation file. This indicates outdated configuration of the Sentry SDK. Use `Sentry.captureRequestError` to instrument the `onRequestError` hook: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#errors-from-nested-react-server-components',
558543
);
559544
}
560545
}

yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12615,14 +12615,6 @@ [email protected], chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.4.1, chalk@^2.4.
1261512615
escape-string-regexp "^1.0.5"
1261612616
supports-color "^5.3.0"
1261712617

12618-
[email protected], chalk@^3.0.0:
12619-
version "3.0.0"
12620-
resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4"
12621-
integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==
12622-
dependencies:
12623-
ansi-styles "^4.1.0"
12624-
supports-color "^7.1.0"
12625-
1262612618
1262712619
version "4.1.0"
1262812620
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.0.tgz#4e14870a618d9e2edd97dd8345fd9d9dc315646a"
@@ -12642,6 +12634,14 @@ chalk@^1.0.0:
1264212634
strip-ansi "^3.0.0"
1264312635
supports-color "^2.0.0"
1264412636

12637+
chalk@^3.0.0:
12638+
version "3.0.0"
12639+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4"
12640+
integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==
12641+
dependencies:
12642+
ansi-styles "^4.1.0"
12643+
supports-color "^7.1.0"
12644+
1264512645
chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2:
1264612646
version "4.1.2"
1264712647
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"

0 commit comments

Comments
 (0)