Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Closed
GorlikItsMe opened this issue Aug 7, 2024 · 14 comments · Fixed by #13603
Closed

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

GorlikItsMe opened this issue Aug 7, 2024 · 14 comments · Fixed by #13603

Comments

@GorlikItsMe
Copy link

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

@GorlikItsMe GorlikItsMe changed the title Sentry cant upload sourcemaps for default next.js project Sentry cant upload sourcemaps in default next.js project Aug 7, 2024
@getsantry
Copy link

getsantry bot commented Aug 7, 2024

Assigning to @getsentry/support for routing ⏲️

@JLuse JLuse transferred this issue from getsentry/sentry Aug 8, 2024
@getsantry getsantry bot moved this from Waiting for: Support to Waiting for: Product Owner in GitHub Issues with 👀 3 Aug 8, 2024
@andreiborza
Copy link
Member

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

@andreiborza
Copy link
Member

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

Image

@getsantry getsantry bot moved this to Waiting for: Community in GitHub Issues with 👀 3 Aug 8, 2024
@GorlikItsMe
Copy link
Author

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

> [email protected] 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.

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3 Aug 8, 2024
@GorlikItsMe
Copy link
Author

Also there is screenshot what I can see in dashboard

Image

@andreiborza
Copy link
Member

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
Copy link

Merynek commented Aug 9, 2024

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 :-(

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Aug 9, 2024
@andreiborza
Copy link
Member

@Merynek are you on Windows too?

@GorlikItsMe
Copy link
Author

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)

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Aug 9, 2024
@Merynek
Copy link

Merynek commented Aug 9, 2024

@Merynek are you on Windows too?

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

@andreiborza
Copy link
Member

@Merynek do you have a reproduction repo for that?

@dually8
Copy link

dually8 commented Sep 4, 2024

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
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
// 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://[email protected]/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

Image

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.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Sep 4, 2024
@andreiborza
Copy link
Member

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

@getsantry getsantry bot removed the status in GitHub Issues with 👀 3 Sep 5, 2024
andreiborza added a commit that referenced this issue Sep 6, 2024
Currently, we use `path.join` to provide sourcemap directories.
On Windows, the resulting strings would use `\` which is an escape
character for glob patterns and thus no sourcemaps would be found.

This fix ensures we use posix paths which glob then handles correctly
on Windows too.

Closes: #13270
Partly fixes: #13288
andreiborza added a commit that referenced this issue Sep 6, 2024
Currently, we use `path.join` to provide sourcemap directories.
On Windows, the resulting strings would use `\` which is an escape
character for glob patterns and thus no sourcemaps would be found.

This fix ensures we use posix paths which glob then handles correctly
on Windows too.

Closes: #13270
Partly fixes: #13288
@GorlikItsMe
Copy link
Author

Tested latest version (8.37.1) and everything works. 🚀
Thanks ❤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants