diff --git a/dev-packages/e2e-tests/test-applications/nextjs-app-dir/assert-build.ts b/dev-packages/e2e-tests/test-applications/nextjs-app-dir/assert-build.ts index 4412714740b0..2129f75d6b16 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-app-dir/assert-build.ts +++ b/dev-packages/e2e-tests/test-applications/nextjs-app-dir/assert-build.ts @@ -8,24 +8,9 @@ const buildStdout = fs.readFileSync('.tmp_build_stdout', 'utf-8'); const buildStderr = fs.readFileSync('.tmp_build_stderr', 'utf-8'); // Assert that there was no funky build time warning when we are on a stable (pinned) version -// if (nextjsVersion !== 'latest' && nextjsVersion !== 'canary') { -// assert.doesNotMatch(buildStderr, /Import trace for requested module/); // This is Next.js/Webpack speech for "something is off" -// } -// 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: -// --- Start logs --- -// ./node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js -// ./node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js -// Critical dependency: the request of a dependency is an expression -// Import trace for requested module: -// ./node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js -// ./node_modules/@opentelemetry/instrumentation/build/esm/platform/node/index.js -// ./node_modules/@opentelemetry/instrumentation/build/esm/platform/index.js -// ./node_modules/@opentelemetry/instrumentation/build/esm/index.js -// ./node_modules/@sentry/node/cjs/index.js -// ./node_modules/@sentry/nextjs/cjs/server/index.js -// ./node_modules/@sentry/nextjs/cjs/index.server.js -// ./app/page.tsx -// --- End logs --- +if (nextjsVersion !== 'latest' && nextjsVersion !== 'canary') { + assert.doesNotMatch(buildStderr, /Import trace for requested module/); // This is Next.js/Webpack speech for "something is off" +} // Assert that all static components stay static and all dynamic components stay dynamic assert.match(buildStdout, /○ \/client-component/); diff --git a/packages/nextjs/src/config/types.ts b/packages/nextjs/src/config/types.ts index 041d815d09d9..43f45ce1bbcf 100644 --- a/packages/nextjs/src/config/types.ts +++ b/packages/nextjs/src/config/types.ts @@ -418,6 +418,7 @@ export type WebpackConfigObject = { output: { filename: string; path: string }; target: string; context: string; + ignoreWarnings?: { module?: RegExp }[]; // Note: The interface for `ignoreWarnings` is larger but we only need this. See https://webpack.js.org/configuration/other-options/#ignorewarnings resolve?: { modules?: string[]; alias?: { [key: string]: string | boolean }; diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 066d26c6d64c..f1228d3ec936 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -73,6 +73,10 @@ export function constructWebpackConfigFunction( // Add a loader which will inject code that sets global values addValueInjectionLoader(newConfig, userNextConfig, userSentryOptions, buildContext); + if (isServer) { + addOtelWarningIgnoreRule(newConfig); + } + let pagesDirPath: string | undefined; const maybePagesDirPath = path.join(projectDir, 'pages'); const maybeSrcPagesDirPath = path.join(projectDir, 'src', 'pages'); @@ -726,3 +730,12 @@ function getRequestAsyncStorageModuleLocation( return undefined; } + +function addOtelWarningIgnoreRule(newConfig: WebpackConfigObjectWithModuleRules): void { + const ignoreRule = { module: /@opentelemetry\/instrumentation/ }; + if (newConfig.ignoreWarnings === undefined) { + newConfig.ignoreWarnings = [ignoreRule]; + } else if (Array.isArray(newConfig.ignoreWarnings)) { + newConfig.ignoreWarnings.push(ignoreRule); + } +}