Skip to content

refactor(nextjs): Change ESM interop. to remove lazy loading#22193

Open
timfish wants to merge 5 commits into
developfrom
timfish/fix/esm-interop
Open

refactor(nextjs): Change ESM interop. to remove lazy loading#22193
timfish wants to merge 5 commits into
developfrom
timfish/fix/esm-interop

Conversation

@timfish

@timfish timfish commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Code checking default like this always points to an ESM/CJS interop issue:

const codeTransformerWebpack = mod.default ?? (mod as unknown as NonNullable<typeof mod.default>);

This is caused by our repo-wide Rollup setting of interop: 'esModule'. This is required for us to be able to monkey patch Node built-ins but causes the above issues with CJS dependencies that use the classic CJS default export (module.exports = fn).

This PR overrides the interop setting for the suspect package and removes the lazy dependency loading.

@timfish timfish changed the title fix(nextjs): Fix ESM interop. to remove lazy loading fix(nextjs): Change ESM interop. to remove lazy loading Jul 10, 2026
@timfish
timfish marked this pull request as ready for review July 11, 2026 13:41
@timfish
timfish requested review from a team as code owners July 11, 2026 13:41
@timfish
timfish requested review from andreiborza, chargome, isaacs, mydea and s1gr1d and removed request for a team July 11, 2026 13:41
cursor[bot]

This comment was marked as outdated.

@timfish timfish changed the title fix(nextjs): Change ESM interop. to remove lazy loading refactor(nextjs): Change ESM interop. to remove lazy loading Jul 11, 2026

@JPeer264 JPeer264 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested if that changes anything. But it sounds valid.

I think we should wait for @chargome though

@timfish

timfish commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

Practicing what I preach 🤣

@timfish
timfish requested a review from a team as a code owner July 16, 2026 11:08
cursor[bot]

This comment was marked as outdated.

@timfish
timfish requested review from chargome and removed request for chargome July 16, 2026 12:13
default?: (options: { instrumentations: InstrumentationConfig[] }) => unknown;
};
const codeTransformerWebpack = mod.default ?? (mod as unknown as NonNullable<typeof mod.default>);
export function sentryOrchestrionWebpackPlugin(options: PluginOptions = {}): ReturnType<typeof codeTransformerWebpack> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The function sentryOrchestrionWebpackPlugin is called without arguments, but its options parameter no longer has a default value, leading to a TypeError when options.instrumentations is accessed.
Severity: HIGH

Suggested Fix

Restore the default value for the options parameter in the sentryOrchestrionWebpackPlugin function signature. Change (options: PluginOptions) to (options: PluginOptions = {}) to prevent options from being undefined when the function is called without arguments.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/server-utils/src/orchestrion/bundler/webpack.ts#L50

Potential issue: The function `sentryOrchestrionWebpackPlugin` is called without
arguments from `packages/nextjs/src/config/webpack.ts`. A recent refactor removed the
default `{}` value for the `options` parameter. Consequently, `options` becomes
`undefined` inside the function. This `undefined` value is passed to
`orchestrionTransformOptions`, which then attempts to access `options.instrumentations`,
causing a `TypeError`. This will crash the webpack build process for Next.js
applications that have the `_experimental.useDiagnosticsChannelInjection` option
enabled.

Also affects:

  • packages/nextjs/src/config/webpack.ts:436~436

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants