Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Critical dependency warning with require-in-the-middle after upgrading to Sentry 8.52.0 in Next.js app #15209

Open
3 tasks done
danielkoller opened this issue Jan 29, 2025 · 34 comments
Labels
Bug Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@danielkoller
Copy link

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.52.0

Framework Version

React 19.0.0 & Next.js 15.1.6

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

  1. Create a Next.js application
  2. Install latest @sentry/nextjs (8.52.0)
  3. Run the development server
  4. Observe the critical dependency warning

Expected Result

No critical dependency warnings during development server startup.

Actual Result

 ⚠ ./node_modules/.pnpm/require-in-the-middle@7.5.0/node_modules/require-in-the-middle/index.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Import trace for requested module:
./node_modules/.pnpm/require-in-the-middle@7.5.0/node_modules/require-in-the-middle/index.js
./node_modules/.pnpm/@opentelemetry+instrumentation@0.56.0_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js
./node_modules/.pnpm/@opentelemetry+instrumentation@0.56.0_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/index.js
./node_modules/.pnpm/@opentelemetry+instrumentation@0.56.0_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/platform/index.js
./node_modules/.pnpm/@opentelemetry+instrumentation@0.56.0_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/index.js
./node_modules/.pnpm/@sentry+opentelemetry@8.52.0_@opentelemetry+api@1.9.0_@opentelemetry+core@1.30.1_@opentelemet_usgluomwp3va5k3mad5pbwdxfm/node_modules/@sentry/opentelemetry/build/cjs/index.js
./node_modules/.pnpm/@sentry+nextjs@8.52.0_@opentelemetry+core@1.30.1_@opentelemetry+api@1.9.0__@opentelemetry+ins_fvm7vkuyikfkbj6gbt6uu4g4sq/node_modules/@sentry/nextjs/build/cjs/server/index.js
./node_modules/.pnpm/@sentry+nextjs@8.52.0_@opentelemetry+core@1.30.1_@opentelemetry+api@1.9.0__@opentelemetry+ins_fvm7vkuyikfkbj6gbt6uu4g4sq/node_modules/@sentry/nextjs/build/cjs/index.server.js
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 29, 2025
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label Jan 29, 2025
@lforst
Copy link
Member

lforst commented Jan 29, 2025

Hi, we'll resolve this warning with the next release!

@danielkoller
Copy link
Author

Awesome, thanks @lforst!

@sousounibajis
Copy link

Hi @lforst,

Since upgrading to @sentry/nextjs@8.52.0, I’m encountering the same "require-in-the-middle" Critical Dependency Warning in Next.js. I saw that you mentioned a fix is planned for the next release.

For the interim solution, could you clarify: 1️⃣ Which is the latest stable release that does not have this issue? Should we downgrade to @sentry/nextjs@8.51.0, or is there a better version? 2️⃣ Would you recommend suppressing the warning using "ignoreWarnings" in next.config.js, or is downgrading a better approach? 3️⃣ What’s the estimated timeline for the fix in the next release?

Thanks in advance for your help! (cc: @getsantry @danielkoller)

@Lms24
Copy link
Member

Lms24 commented Jan 30, 2025

@sousounibajis just jumping in for Luca real quick:

  • 8.51.0 should still be good as we only noticed this with 8.52.0
  • I'm starting the 8.52.1 release right now which fixes this issue. It should be out in a couple of hours.

Lms24 added a commit that referenced this issue Jan 30, 2025
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 30, 2025
@Lms24
Copy link
Member

Lms24 commented Jan 30, 2025

8.52.1 was just released, let me know if the error still persists!

Sorry for the troubles everyone!

@colaquecez
Copy link

colaquecez commented Jan 30, 2025

Hey, I'm getting the same error using 8.51.0

Import trace for requested module:
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/index.js
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/index.js
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/index.js
../../node_modules/@prisma/instrumentation/dist/chunk-PVBRMQBZ.js
../../node_modules/@prisma/instrumentation/dist/index.js
../../node_modules/@sentry/node/build/cjs/integrations/tracing/prisma.js
../../node_modules/@sentry/node/build/cjs/index.js
../../node_modules/@sentry/nextjs/build/cjs/index.server.js
./app/global-error.tsx

../../node_modules/require-in-the-middle/index.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Import trace for requested module:
../../node_modules/require-in-the-middle/index.js
../../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/opentelemetry/build/cjs/index.js
../../node_modules/@sentry/nextjs/build/cjs/server/index.js
../../node_modules/@sentry/nextjs/build/cjs/index.server.js
./app/global-error.tsx
 GET / 200 in 49083ms
 ⚠ ../../node_modules/@prisma/instrumentation/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/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/index.js
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/index.js
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/index.js
../../node_modules/@prisma/instrumentation/dist/chunk-PVBRMQBZ.js
../../node_modules/@prisma/instrumentation/dist/index.js
../../node_modules/@sentry/node/build/cjs/integrations/tracing/prisma.js
../../node_modules/@sentry/node/build/cjs/index.js
../../node_modules/@sentry/nextjs/build/cjs/index.server.js
./app/global-error.tsx
yarn why @prisma/instrumentation       
yarn why v1.22.22
[1/4] 🤔  Why do we have the module "@prisma/instrumentation"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "@prisma/instrumentation@5.22.0"
info Reasons this module exists
   - "@sentry#nextjs#@sentry#node" depends on it
   - Hoisted from "@sentry#nextjs#@sentry#node#@prisma#instrumentation"
info Disk size without dependencies: "1.98MB"
info Disk size with unique dependencies: "7.83MB"
info Disk size with transitive dependencies: "23.56MB"
info Number of shared dependencies: 23
✨  Done in 0.46s.

@Lms24
Copy link
Member

Lms24 commented Jan 30, 2025

I'm getting the same error using 8.51.0

@colaquecez does 8.52.1 fix it for you?

@colaquecez
Copy link

colaquecez commented Jan 30, 2025

Hey @Lms24, it doesn't:

"@sentry/nextjs": "8.52.1"

Import trace for requested module:
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/index.js
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/index.js
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/index.js
../../node_modules/@prisma/instrumentation/dist/chunk-PVBRMQBZ.js
../../node_modules/@prisma/instrumentation/dist/index.js
../../node_modules/@sentry/node/build/cjs/integrations/tracing/prisma.js
../../node_modules/@sentry/node/build/cjs/index.js
../../node_modules/@sentry/nextjs/build/cjs/index.server.js
./app/global-error.tsx

../../node_modules/require-in-the-middle/index.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Import trace for requested module:
../../node_modules/require-in-the-middle/index.js
../../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/opentelemetry/build/cjs/index.js
../../node_modules/@sentry/nextjs/build/cjs/server/index.js
../../node_modules/@sentry/nextjs/build/cjs/index.server.js
./app/global-error.tsx
 GET / 200 in 52182ms
 ⚠ ../../node_modules/@prisma/instrumentation/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/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/index.js
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/platform/index.js
../../node_modules/@prisma/instrumentation/node_modules/@opentelemetry/instrumentation/build/esm/index.js
../../node_modules/@prisma/instrumentation/dist/chunk-PVBRMQBZ.js
../../node_modules/@prisma/instrumentation/dist/index.js
../../node_modules/@sentry/node/build/cjs/integrations/tracing/prisma.js
../../node_modules/@sentry/node/build/cjs/index.js
../../node_modules/@sentry/nextjs/build/cjs/index.server.js
./app/global-error.tsx

../../node_modules/require-in-the-middle/index.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Import trace for requested module:
../../node_modules/require-in-the-middle/index.js
../../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/opentelemetry/build/cjs/index.js
../../node_modules/@sentry/nextjs/build/cjs/server/index.js
../../node_modules/@sentry/nextjs/build/cjs/index.server.js
[1/4] 🤔  Why do we have the module "@prisma/instrumentation"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "@prisma/instrumentation@5.22.0"
info Reasons this module exists
   - "@sentry#nextjs#@sentry#node" depends on it
   - Hoisted from "@sentry#nextjs#@sentry#node#@prisma#instrumentation"
info Disk size without dependencies: "1.98MB"
info Disk size with unique dependencies: "7.83MB"
info Disk size with transitive dependencies: "23.56MB"
info Number of shared dependencies: 23
✨  Done in 0.48s.

@Lms24 Lms24 reopened this Jan 30, 2025
@ComeOnNiklas
Copy link

ComeOnNiklas commented Feb 26, 2025

I am able to reproduce this issue in my NextJS application. It seems to me like the issue is related to using Turbopack as I am not seeing the same warning using Webpack.

Steps to reproduce:

  • Create new NextJS app (npx create-next-app@latest sentry-issue-repro --ts --app --src-dir --turbopack --use-pnpm)
  • Run the Sentry wizard (npx @sentry/wizard@latest -i nextjs)
  • Run the application using Turbopack

I created this repository with a reproducible example

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 26, 2025
@chargome
Copy link
Member

Thanks @ComeOnNiklas , didn't realize this was related to turbopack! Pleaser refer to #8105

@spathon
Copy link

spathon commented Mar 4, 2025

@chargome I have not had time but might have some next week to make some proper test.
We are not using turbopack but it is a big monorepo using turborepo

@cording12
Copy link

This error was getting annoying - the Sentry team appear to be addressing this already, #8105, however there are a couple things you can do to silence this warning.

Don't use Turbo

Running next dev instead of next dev --turbo will fix the issue, but then you lose out on Turbo

Add an ignoreWarnings webpack config

In your next.config.mjs file, add:

const nextConfig = {
  reactStrictMode: true,
  transpilePackages: ["@aiq/ui"],
  // TODO: Remove this once it's fixed by Sentry
  webpack: (config, { isServer }) => {
    if (isServer) {
      config.ignoreWarnings = [
        { message: /Package import-in-the-middle can't be external/ },
      ]
    }
    return config
  },
  // Adding the webpack config creates a new warning, stating "Webpack is configured while Turbopack is not"
  // This just silences that warning too
  experimental: {
    turbo: {},
  },
}

@geovanygameros
Copy link

For me, I remove the warnings by adding these lines to the .npmrc and install the dependencies again:

public-hoist-pattern[]=*import-in-the-middle*
public-hoist-pattern[]=*require-in-the-middle*

For reference: vercel/next.js#76247

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug Package: nextjs Issues related to the Sentry Nextjs SDK
Projects
Status: No status
Development

No branches or pull requests