diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 94db1cca621d..30532b354360 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -433,7 +433,7 @@ export function constructWebpackConfigFunction({ // Orchestrion code-transform loader — Node server runtime only, never the edge compilation if (runtime === 'server' && userSentryOptions._experimental?.useDiagnosticsChannelInjection) { - newConfig.plugins.push(sentryOrchestrionWebpackPlugin() as WebpackPluginInstance); + newConfig.plugins.push(sentryOrchestrionWebpackPlugin() as unknown as WebpackPluginInstance); } return newConfig; diff --git a/packages/server-utils/package.json b/packages/server-utils/package.json index 749dd600cb80..cd0ba30a9c90 100644 --- a/packages/server-utils/package.json +++ b/packages/server-utils/package.json @@ -39,12 +39,11 @@ }, "./orchestrion/vite": { "types": "./build/types/orchestrion/bundler/vite.d.ts", - "import": "./build/esm/orchestrion/bundler/vite.js" + "default": "./build/esm/orchestrion/bundler/vite.js" }, "./orchestrion/webpack": { "types": "./build/types/orchestrion/bundler/webpack.d.ts", - "import": "./build/esm/orchestrion/bundler/webpack.js", - "require": "./build/cjs/orchestrion/bundler/webpack.js" + "default": "./build/esm/orchestrion/bundler/webpack.js" }, "./orchestrion/import-hook": { "import": "./build/orchestrion/import-hook.mjs" diff --git a/packages/server-utils/src/orchestrion/bundler/webpack.ts b/packages/server-utils/src/orchestrion/bundler/webpack.ts index 04eb56a2c6b9..860a1cc046bc 100644 --- a/packages/server-utils/src/orchestrion/bundler/webpack.ts +++ b/packages/server-utils/src/orchestrion/bundler/webpack.ts @@ -5,6 +5,7 @@ import { createRequire } from 'node:module'; import { dirname } from 'node:path'; import type { InstrumentationConfig } from '@apm-js-collab/code-transformer'; import { SENTRY_INSTRUMENTATIONS } from '../config'; +import codeTransformer from '@apm-js-collab/code-transformer-bundler-plugins/webpack'; // Both branches use `createRequire` (never alias the CJS `require`) so bundlers consuming this // module don't emit a "Critical dependency" warning. @@ -46,10 +47,6 @@ export function getSentryInstrumentations(): InstrumentationConfig[] { * does NOT inject the `__SENTRY_ORCHESTRION__.bundler` marker — that would disable the runtime * module hook, which externalized packages still need (hybrid setup). */ -export function sentryOrchestrionWebpackPlugin(): unknown { - const mod = getOrchestrionRequire()('@apm-js-collab/code-transformer-bundler-plugins/webpack') as { - default?: (options: { instrumentations: InstrumentationConfig[] }) => unknown; - }; - const codeTransformerWebpack = mod.default ?? (mod as unknown as NonNullable); - return codeTransformerWebpack({ instrumentations: SENTRY_INSTRUMENTATIONS }); +export function sentryOrchestrionWebpackPlugin(): ReturnType { + return codeTransformer({ instrumentations: SENTRY_INSTRUMENTATIONS }); } diff --git a/packages/server-utils/src/orchestrion/runtime/register.ts b/packages/server-utils/src/orchestrion/runtime/register.ts index 157672c8c3cd..4850915aaee6 100644 --- a/packages/server-utils/src/orchestrion/runtime/register.ts +++ b/packages/server-utils/src/orchestrion/runtime/register.ts @@ -84,9 +84,6 @@ export function registerDiagnosticsChannelInjection(options?: RegisterDiagnostic nodeRequire = createRequire(import.meta.url); /*! rollup-include-esm-only-end */ - const tracingHooksDir = options?.tracingHooksDir; - const requireFromHooksDir = tracingHooksDir ? createRequire(thisModuleUrl) : undefined; - // `Module.registerHooks` / `Module.register` are newer than the @types/node // we build against, hence the cast. const mod = Module as unknown as { @@ -105,11 +102,7 @@ export function registerDiagnosticsChannelInjection(options?: RegisterDiagnostic // We require() the module here so that we can synchronously load it, // including from a CommonJS Sentry build, without bundlers pulling in. // All versions in stableSyncHooks support this. - const { initialize, resolve, load } = ( - requireFromHooksDir - ? requireFromHooksDir(`${tracingHooksDir}/hook-sync.mjs`) - : nodeRequire('@apm-js-collab/tracing-hooks/hook-sync.mjs') - ) as { + const { initialize, resolve, load } = nodeRequire('@apm-js-collab/tracing-hooks/hook-sync.mjs') as { initialize: (opts: { instrumentations: unknown }) => void; resolve: unknown; load: unknown; @@ -124,10 +117,7 @@ export function registerDiagnosticsChannelInjection(options?: RegisterDiagnostic // `Module.register` resolves ESM-style: a bare package specifier is resolved against // `parentURL`, but a filesystem path (the `tracingHooksDir` override) is not a valid ESM // specifier and must be passed as a file:// URL. - const hookSpecifier = tracingHooksDir - ? pathToFileURL(`${tracingHooksDir}/hook.mjs`).href - : '@apm-js-collab/tracing-hooks/hook.mjs'; - mod.register(hookSpecifier, { + mod.register('@apm-js-collab/tracing-hooks/hook.mjs', { parentURL: thisModuleUrl, data: { instrumentations: SENTRY_INSTRUMENTATIONS }, });