Skip to content

Conditional require calls are hoisted incorrectly #6943

Description

@beckerei

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.33.0

Framework Version

Next 13.1.5

Link to Sentry event

No response

SDK Setup

Sentry.init({dsn: 'foobar',
environment,enabled: !!environment&&['staging','production'].includes(environment),tracesSampleRate: 0.2,tracesSampler: (ctx)=>!ctx.transactionContext.name.includes('healthz'),beforeSend(event){if(!event.request?.cookies)returnevent;const{ cookies }=event.request;Object.keys(cookies).forEach((key)=>{if(key.toLowerCase().includes('session')){cookies[key]='[Redacted]';}});returnevent;},});

Steps to Reproduce

  1. conditionally use a require() call
  2. start prod or dev server of next in a case where the condition should be false

Expected Result

The file should not be required

Actual Result

The file will be required regardless of the surrounding if-statement


Our understanding is that this behavior was introduced within the following PR
#6685

Enabeling transformMixedEsModules
See also rollup/plugins#1177 which indicates that the rollup plugin can't fix this.

This is the recommended way to run MSW in your local env, see example https://github.com/vercel/next.js/blob/canary/examples/with-msw/pages/_app.tsx

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions