Skip to content

Mixing node and edge instrumentations causes webpack errors #11823

@r34son

Description

@r34son

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

8.0.0-beta.4

Framework Version

No response

Link to Sentry event

No response

SDK Setup

import { init } from '@sentry/nextjs';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import { SENTRY_CAPTURE_RATE, SENTRY_DSN } from 'sentry.constants.mjs';

export function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
init({
dsn: SENTRY_DSN,
debug: false,
tracesSampleRate: SENTRY_CAPTURE_RATE,
profilesSampleRate: SENTRY_CAPTURE_RATE,
environment: process.env.ENV,
integrations: [nodeProfilingIntegration()],
});
}
if (process.env.NEXT_RUNTIME === 'edge') {
init({
dsn: SENTRY_DSN,
tracesSampleRate: SENTRY_CAPTURE_RATE,
environment: process.env.ENV,
});
}
}

Steps to Reproduce

https://docs.sentry.io/platforms/javascript/guides/nextjs/migration/v7-to-v8/#opentelemetry-instrumentation
3 step says to remove instrumentation.node.ts. Tried it and it causes errors because now webpack emits one chunk for edge and node instrumentation. And it fails because node api is not available in edge.

Before i was using:

export async function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    await import('./instrumentation.node');
  }
  if (process.env.NEXT_RUNTIME === 'edge') {
    await import('./instrumentation.edge');
  }
}

Should i use it? but i am not sure that this dynamic imports are good way to init sdk

Expected Result

Build without errors

Actual Result

next build

▲ Next.js 14.3.0-canary.28

  • Environments: .env.local
  • Experiments (use with caution):
    · webpackBuildWorker
    · instrumentationHook
    · preloadEntriesOnStart

Creating an optimized production build ...
Failed to compile.

./node_modules/.pnpm/[email protected]/node_modules/detect-libc/lib/detect-libc.js:6:1
Module not found: Can't resolve 'child_process'
4 | 'use strict';
5 |

6 | const childProcess = require('child_process');
| ^
7 | const { isLinux, getReport } = require('./process');
8 | const { LDD_PATH, readFile, readFileSync } = require('./filesystem');
9 |

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/.pnpm/@sentry[email protected]/node_modules/@sentry/profiling-node/lib/esm/index.js
./src/instrumentation.ts

./node_modules/.pnpm/[email protected]/node_modules/detect-libc/lib/filesystem.js:6:1
Module not found: Can't resolve 'fs'
4 | 'use strict';
5 |

6 | const fs = require('fs');
| ^
7 |
8 | /**
9 | * The path where we can find the ldd

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/.pnpm/[email protected]/node_modules/detect-libc/lib/detect-libc.js
./node_modules/.pnpm/@sentry[email protected]/node_modules/@sentry/profiling-node/lib/esm/index.js
./src/instrumentation.ts

node:module
Module build failed: UnhandledSchemeError: Reading from "node:module" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
at /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401799
at Hook.eval [as callAsync] (eval at create (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:13:28858), :6:1)
at Object.processResource (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401724)
at processResource (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)
at iteratePitchingLoaders (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)
at runLoaders (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)
at NormalModule.doBuild (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/[email protected]@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401586)
at NormalModule.build (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:403614)
at /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:82061
at NormalModule.needBuild (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:407746)

Import trace for requested module:
node:module
./node_modules/.pnpm/@sentry[email protected]/node_modules/@sentry/profiling-node/lib/esm/index.js

node:path
Module build failed: UnhandledSchemeError: Reading from "node:path" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
at /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401799
at Hook.eval [as callAsync] (eval at create (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:13:28858), :6:1)
at Object.processResource (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401724)
at processResource (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)
at iteratePitchingLoaders (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)
at runLoaders (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)
at NormalModule.doBuild (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/[email protected]@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401586)
at NormalModule.build (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:403614)
at /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:82061
at NormalModule.needBuild (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:407746)

Import trace for requested module:
node:path
./node_modules/.pnpm/@sentry[email protected]/node_modules/@sentry/profiling-node/lib/esm/index.js

node:url
Module build failed: UnhandledSchemeError: Reading from "node:url" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
at /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401799
at Hook.eval [as callAsync] (eval at create (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:13:28858), :6:1)
at Hook.CALL_ASYNC_DELEGATE [as callAsync] (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/[email protected]@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:13:26012)
at Object.processResource (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401724)
at processResource (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)
at iteratePitchingLoaders (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)
at runLoaders (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)
at NormalModule.doBuild (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/[email protected]@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401586)
at NormalModule.build (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:403614)
at /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright[email protected]_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:82061

Import trace for requested module:
node:url
./node_modules/.pnpm/@sentry[email protected]/node_modules/@sentry/profiling-node/lib/esm/index.js

Build failed because of webpack errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nextjsIssues related to the Sentry Nextjs SDK

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions