8000 feat(nextjs): Mute webpack warnings about critical dependencies insid… · basarat/sentry-javascript@7eef5df · GitHub
[go: up one dir, main page]

Skip to content

Commit 7eef5df

Browse files
authored
feat(nextjs): Mute webpack warnings about critical dependencies inside @opentelemetry/instrumentation (getsentry#11810)
1 parent eec70b5 commit 7eef5df

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

dev-packages/e2e-tests/test-applications/nextjs-app-dir/assert-build.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,9 @@ const buildStdout = fs.readFileSync('.tmp_build_stdout', 'utf-8');
88
const buildStderr = fs.readFileSync('.tmp_build_stderr', 'utf-8');
99

1010
// Assert that there was no funky build time warning when we are on a stable (pinned) version
11-
// if (nextjsVersion !== 'latest' && nextjsVersion !== 'canary') {
12-
// assert.doesNotMatch(buildStderr, /Import trace for requested module/); // This is Next.js/Webpack speech for "something is off"
13-
// }
14-
// Note(lforst): I disabled this for the time being to figure out OTEL + Next.js - Next.js is currently complaining about a critical import in the @opentelemetry/instrumentation package. E.g:
15-
// --- Start logs ---
16-
// ./node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js
17-
// ./node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js
18-
// Critical dependency: the request of a dependency is an expression
19-
// Import trace for requested module:
20-
// ./node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js
21-
// ./node_modules/@opentelemetry/instrumentation/build/esm/platform/node/index.js
22-
// ./node_modules/@opentelemetry/instrumentation/build/esm/platform/index.js
23-
// ./node_modules/@opentelemetry/instrumentation/build/esm/index.js
24-
// ./node_modules/@sentry/node/cjs/index.js
25-
// ./node_modules/@sentry/nextjs/cjs/server/index.js
26-
// ./node_modules/@sentry/nextjs/cjs/index.server.js
27-
// ./app/page.tsx
28-
// --- End logs ---
11+
if (nextjsVersion !== 'latest' && nextjsVersion !== 'canary') {
12+
assert.doesNotMatch(buildStderr, /Import trace for requested module/); // This is Next.js/Webpack speech for "something is off"
13+
}
2914

3015
// Assert that all static components stay static and all dynamic components stay dynamic
3116
assert.match(buildStdout, / \/client-component/);

packages/nextjs/src/config/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ export type WebpackConfigObject = {
418418
output: { filename: string; path: string };
419419
target: string;
420420
context: string;
421+
ignoreWarnings?: { module?: RegExp }[]; // Note: The interface for `ignoreWarnings` is larger but we only need this. See https://webpack.js.org/configuration/other-options/#ignorewarnings
421422
resolve?: {
422423
modules?: string[];
423424
alias?: { [key: string]: string | boolean };

packages/nextjs/src/config/webpack.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export function constructWebpackConfigFunction(
7373
// Add a loader which will inject code that sets global values
7474
addValueInjectionLoader(newConfig, userNextConfig, userSentryOptions, buildContext);
7575

76+
if (isServer) {
77+
addOtelWarningIgnoreRule(newConfig);
78+
}
79+
7680
let pagesDirPath: string | undefined;
7781
const maybePagesDirPath = path.join(projectDir, 'pages');
7882
const maybeSrcPagesDirPath = path.join(projectDir, 'src', 'pages');
@@ -726,3 +730,12 @@ function getRequestAsyncStorageModuleLocation(
726730

727731
return undefined;
728732
}
733+
734+
function addOtelWarningIgnoreRule(newConfig: WebpackConfigObjectWithModuleRules): void {
735+
const ignoreRule = { module: /@opentelemetry\/instrumentation/ };
736+
if (newConfig.ignoreWarnings === undefined) {
737+
newConfig.ignoreWarnings = [ignoreRule];
738+
} else if (Array.isArray(newConfig.ignoreWarnings)) {
739+
newConfig.ignoreWarnings.push(ignoreRule);
740+
}
741+
}

0 commit comments

Comments
 (0)
0