getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.86k stars 1.55k forks source link

@sentry/next.js and @sentry/cli failing after Next.js 12.2.0 upgrade #5366

Closed heldr closed 2 years ago

heldr commented 2 years ago

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

Framework Version

7.5.0

Link to Sentry event

No response

Steps to Reproduce

After upgrading to Next.js 12.2.0, webpack plugin withSentryConfig seems to fail when CLI tries to update and upload source maps.

Expected Result

CLI is expected to recognize Node.js modules.

Actual Result

Getting this error CleanShot 2022-07-05 at 11 28 37

even if all those modules are already skipped on non-server builds. CleanShot 2022-07-05 at 11 33 27

AbhiPrasad commented 2 years ago

Hey thanks for writing in, we are taking a look! In the mean time, to help us debug, could you provide your webpack version and your next.config.js if possible? A repro app of some sort will also help a lot!

I have a quick theory that https://nextjs.org/docs/api-reference/edge-runtime is causing issues here. As per their section on unsupported APIs:

Native Node.js APIs are not supported. For example, you can't read or write to the filesystem

Not sure why they would be running at build time though, so maybe I'm wrong 🤔.

heldr commented 2 years ago

@AbhiPrasad you are actually right!

I just setup one codesandbox example where commenting the following edge api runtime avoids the issue.

export const config = {
  runtime: 'experimental-edge'
};

I'm going to ignore those edge functions on Sentry config on meantime.

how to debug sandbox

Edge api function example. https://codesandbox.io/s/headless-sun-xqrqgj?file=/pages/api/geoip.js

please set the following env var secrets:

SENTRY_ORG
SENTRY_PROJECT
SENTRY_AUTH_TOKEN
NEXT_PUBLIC_SENTRY_DSN

then open a new terminal and run

yarn build
AbhiPrasad commented 2 years ago

See https://github.com/vercel/next.js/issues/36776 for more details. Yeah we don't support middleware at the moment, this is being tracked here: https://github.com/getsentry/sentry-javascript/issues/4206

heldr commented 2 years ago

Apparently adding edge route api to ignoreFile and ignore array CLI config doesn't avoid issue.

heldr commented 2 years ago

Bug reported was fixed on Next.js 12.2.1 by this changed https://github.com/vercel/next.js/pull/38234