getsentry / sentry-javascript

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

Sentry cant upload sourcemaps in default next.js project #13270

Closed GorlikItsMe closed 6 days ago

GorlikItsMe commented 1 month ago

Environment

SaaS (https://sentry.io/)

What are you trying to accomplish?

I want to add sentry to my next.js project

How are you getting stuck?

For some reason sentry cant upload sourcemaps during build time. Because of that, you cant see the source code in the sentry dashboard.

I created example repository: https://github.com/GorlikItsMe/nextjs-sentry-dont-work

When i enabled logs (silent: false in next.config.mjs) i saw this:

[@sentry/nextjs - Node.js] Info: Sending telemetry data on issues and performance to Sentry. To disable telemetry, set `options.telemetry` to `false`.
[@sentry/nextjs - Node.js] Warning: Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option.
[@sentry/nextjs - Edge] Info: Sending telemetry data on issues and performance to Sentry. To disable telemetry, set `options.telemetry` to `false`.
[@sentry/nextjs - Edge] Warning: Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option.
[@sentry/nextjs - Client] Info: Sending telemetry data on issues and performance to Sentry. To disable telemetry, set `options.telemetry` to `false`.
[@sentry/nextjs - Client] Warning: Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option.

Thank you in advance for any advice

Where in the product are you?

Unknown

Link

No response

DSN

No response

Version

No response

getsantry[bot] commented 1 month ago

Assigning to @getsentry/support for routing ⏲️

andreiborza commented 1 month ago

Hi, could you please paste your build output logs? Thanks for the reproduction repo, we'll take a look.

andreiborza commented 1 month ago

I have tried out your repo but cannot reproduce this issue. Do you have your SENTRY_AUTH_TOKEN set in .env?

Image

GorlikItsMe commented 1 month ago

Hi, could you please paste your build output logs? Thanks for the reproduction repo, we'll take a look.

Full build logs:

PS D:\temp\nextjs-and-sentry-dont-work> npm run build

> nextjs-and-sentry-dont-work@0.1.0 build
> next build

  ▲ Next.js 14.2.5
  - Environments: .env
  - Experiments (use with caution):
    · instrumentationHook

   Creating an optimized production build ...
[@sentry/nextjs - Node.js] Info: Sending telemetry data on issues and performance to Sentry. To disable telemetry, set `options.telemetry` to `false`.
[@sentry/nextjs - Node.js] Warning: Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option.
[@sentry/nextjs - Edge] Info: Sending telemetry data on issues and performance to Sentry. To disable telemetry, set `options.telemetry` to `false`.
[@sentry/nextjs - Edge] Warning: Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option.
[@sentry/nextjs - Client] Info: Sending telemetry data on issues and performance to Sentry. To disable telemetry, set `options.telemetry` to `false`.
[@sentry/nextjs - Client] Warning: Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option.
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
 ✓ Generating static pages (6/6)
 ✓ Collecting build traces
 ✓ Finalizing page optimization

Route (app)                              Size     First Load JS
┌ ○ /                                    5.52 kB         188 kB
├ ○ /_not-found                          1.02 kB         183 kB
├ ƒ /api/sentry-example-api              0 B                0 B
└ ○ /sentry-example-page                 2.03 kB         184 kB
+ First Load JS shared by all            182 kB
  ├ chunks/449-d179011c12838fef.js       89.9 kB
  ├ chunks/52774a7f-ab0852fb3e7c5017.js  35.9 kB
  ├ chunks/fd9d1056-1ddaa04915180e67.js  53.8 kB
  └ other shared chunks (total)          2.54 kB

○  (Static)   prerendered as static content
ƒ  (Dynamic)  server-rendered on demand

Machine: win10

Do you have your SENTRY_AUTH_TOKEN set in .env?

Yes token is saved in .env I removed just for test and saw different error:

[@sentry/nextjs - Node.js] Warning: No auth token provided. Will not create release. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/

Soo sentry can reach token.

GorlikItsMe commented 1 month ago

Also there is screenshot what I can see in dashboard

Image

andreiborza commented 1 month ago

hey @GorlikItsMe, we had another look at this and it looks like it's an issue with how we use glob in combination with you being on Windows. We filed a new issue to tackle this.

Merynek commented 1 month ago

I have a same problem with sourcemaps, before nextJS I used a only @sentry/webpack-plugin and it works, In documentation is that @sentry/nextjs has this lbb under the hood. So I dont know where the problem is :-(

andreiborza commented 1 month ago

@Merynek are you on Windows too?

GorlikItsMe commented 1 month ago

Now I tried to run build using WSL The result is the same - sentry can't find any matching sources (Yes I removed node_modules and .next before testing)

Merynek commented 1 month ago

@Merynek are you on Windows too?

Yes!, but on CI/CD is linux so, mby its not the system problem

andreiborza commented 1 month ago

@Merynek do you have a reproduction repo for that?

dually8 commented 1 week ago

I was following along with the workshop today and I've been running into the same issue with the same error messages. My setup is practically the same (see below). I've confirmed that the .js.map files are both created and the corresponding .js files have the //# sourceMappingURL=... at the end of the file. For what it's worth, I'm on Windows 10 using Node v20.

[@sentry/nextjs - Node.js] Info: Using environment variables configured in ".env.sentry-build-plugin".
[@sentry/nextjs - Node.js] Info: Sending telemetry data on issues and performance to Sentry. To disable telemetry, set `options.telemetry` to `false`.
[@sentry/nextjs - Node.js] Warning: Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option.
[@sentry/nextjs - Edge] Info: Using environment variables configured in ".env.sentry-build-plugin".
[@sentry/nextjs - Edge] Info: Sending telemetry data on issues and performance to Sentry. To disable telemetry, set `options.telemetry` to `false`.
[@sentry/nextjs - Edge] Warning: Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option.
[@sentry/nextjs - Client] Info: Using environment variables configured in ".env.sentry-build-plugin".
[@sentry/nextjs - Client] Info: Sending telemetry data on issues and performance to Sentry. To disable telemetry, set `options.telemetry` to `false`.
[@sentry/nextjs - Client] Warning: Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option.
next.config.mjs ```javascript import { withSentryConfig } from '@sentry/nextjs'; /** @type {import('next').NextConfig} */ const nextConfig = { async redirects() { return [ { source: "/", destination: "/manage", permanent: true, }, ]; }, }; export default withSentryConfig( nextConfig, { // For all available options, see: // https://github.com/getsentry/sentry-webpack-plugin#options org: "my-org", project: "sentry-workshop", authToken: process.env.SENTRY_AUTH_TOKEN, // Only print logs for uploading source maps in CI silent: false, // For all available options, see: // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/ // Upload a larger set of source maps for prettier stack traces (increases build time) widenClientFileUpload: true, // Automatically annotate React components to show their full name in breadcrumbs and session replay reactComponentAnnotation: { enabled: true, }, // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers. // This can increase your server load as well as your hosting bill. // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client- // side errors will fail. tunnelRoute: "/monitoring", // Hides source maps from generated client bundles hideSourceMaps: true, // Automatically tree-shake Sentry logger statements to reduce bundle size disableLogger: true, // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.) // See the following for more information: // https://docs.sentry.io/product/crons/ // https://vercel.com/docs/cron-jobs automaticVercelMonitors: true, } ); ```
sentry.client.config.ts ```typescript // This file configures the initialization of Sentry on the client. // The config you add here will be used whenever a users loads a page in their browser. // https://docs.sentry.io/platforms/javascript/guides/nextjs/ import * as Sentry from '@sentry/nextjs'; Sentry.init({ dsn: 'https://xxx@xxx.ingest.us.sentry.io/xxx', // Add optional integrations for additional features integrations: [ Sentry.replayIntegration(), Sentry.feedbackIntegration({ colorScheme: 'system', }), ], // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control. tracesSampleRate: 1, // Define how likely Replay events are sampled. // This sets the sample rate to be 10%. You may want this to be 100% while // in development and sample at a lower rate in production replaysSessionSampleRate: 0.1, // Define how likely Replay events are sampled when an error occurs. replaysOnErrorSampleRate: 1.0, // Setting this option to true will print useful information to the console while you're setting up Sentry. debug: false, }); ```
Sentry Images ![Image](https://github.com/user-attachments/assets/1f28c207-3d0f-4d25-8850-ba7dd87b8c5b) ![Image](https://github.com/user-attachments/assets/7f7c2a82-9f41-45c1-b5b1-dc0ef2667d9c)

EDIT: I ran this entire setup through WSL (Ubuntu 22.04) a moment ago and the sourcemaps upload successfully and the client code is viewable as intended, so, at least for me, this seems to be related to #13288.

andreiborza commented 1 week ago

@dually8 thanks for providing more info. I'll take a look at fixing this for windows.