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

NuxtJS: Source map deletion after upload #13632

Closed
SVV-team opened this issue Sep 9, 2024 · 14 comments
Closed

NuxtJS: Source map deletion after upload #13632

SVV-team opened this issue Sep 9, 2024 · 14 comments
Labels
Package: nuxt Issues related to the Sentry Nuxt SDK

Comments

@SVV-team
Copy link

SVV-team commented Sep 9, 2024

Problem Statement

If source map upload enabled, in production we can see source code (Google Chrome > DevTools > Source) (This is not good)

When source map disable its look like

Solution Brainstorm

Maybe we can generate source map to another folder using separate command?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Sep 9, 2024
@SVV-team SVV-team changed the title [NuxtJS] Source map deletion after upload NuxtJS: Source map deletion after upload Sep 9, 2024
@chargome
Copy link
Member

chargome commented Sep 9, 2024

Hey @SVV-team, assuming you are using the @sentry/nuxt sdk you can make use of https://www.npmjs.com/package/@sentry/vite-plugin/v/2.14.2#sourcemapsfilestodeleteafterupload

@getsantry getsantry bot removed the status in GitHub Issues with 👀 3 Sep 9, 2024
@AbhiPrasad AbhiPrasad added the Package: nuxt Issues related to the Sentry Nuxt SDK label Sep 9, 2024
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Sep 9, 2024
@SVV-team
Copy link
Author

SVV-team commented Sep 9, 2024

Hey @SVV-team, assuming you are using the @sentry/nuxt sdk you can make use of https://www.npmjs.com/package/@sentry/vite-plugin/v/2.14.2#sourcemapsfilestodeleteafterupload

Deletion working, but....
Used config

 sentry: {
    debug: true,
    sourceMapsUploadOptions: {
      sourcemaps: {
        filesToDeleteAfterUpload: ['.output/**/*.map'],
      }
    },
  },

After deploy to production sentry handle many errors
ENOENT: no such file or directory, open '.output/public/content/B8u3bkn1.js.map'

Image

@andreiborza
Copy link
Member

hi @SVV-team, could you please link to one of those issues?

@SVV-team
Copy link
Author

hi @SVV-team, could you please link to one of those issues?

https://svv-team.sentry.io/share/issue/db391adafe1148bda0acdf3c9f36fe61/

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

@SVV-team would mind sharing your nuxt.config.ts?

@SVV-team
Copy link
Author

SVV-team commented Sep 10, 2024

@SVV-team would mind sharing your nuxt.config.ts?

export default defineNuxtConfig({
  modules: [
    '@pinia/nuxt',
    '@nuxtjs/i18n', 
    '@nuxtjs/robots',
    '@nuxt/image',
    '@nuxtjs/device',
    'nuxt-gtag',
    'nuxt-schema-org',
    'nuxt-multi-tenancy',
    '@nuxt/scripts',
    '@nuxt/icon',
    'nuxt-rating',
    '@sentry/nuxt/module',
  ],


  sentry: {
    debug: true,
    sourceMapsUploadOptions: {
      org: '',
      project: '',
      sourcemaps: {
        filesToDeleteAfterUpload: ['.output/**/*.map'],
      },
      authToken:'',
    },
  },

  runtimeConfig: {
    public: {
    ....
    },
  }
})

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

s1gr1d commented Sep 10, 2024

When disabling sourcemaps, the content folder is still visible in the devtools. I don't know what content does exactly under the hood but can you try not deleting every sourcemap in .output? Does it make a difference if you keep content?

@afdolriski
Copy link

afdolriski commented Oct 13, 2024

same here, looks like there are reference to source map from the generated file:
1RmAovpz.js:

import{aO as t,aC as n,aD as o,aR as r}from"./DIuzRh7i.js";(function(){try.....
//# sourceMappingURL=1RmAovpz.js.map

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Oct 13, 2024
@chargome
Copy link
Member

@afdolriski can you paste your nuxt config here?

@rymdkapten
Copy link

rymdkapten commented Oct 15, 2024

Hi,

running into a similiar issue, but using Nuxt 3, I believe the issue is the same though.
The sourcemap URL is appended to each file as such:

//# sourceMappingURL=filename.js.map

There is an option in both nitro and vite that can be set to hide these; in case you don't want to release them publicly.

For vite it is set like such in nuxt.config.ts:

vite: {
  build: {
    sourcemap: 'hidden',
  },
}

And for nitro (note the capital M here):

nitro: {
  sourceMap: 'hidden',
},

However, it seems like the @sentry/nuxt module overwrites both these options.

Vite is overwritten here:

viteInlineConfig.build.sourcemap = true;

While nitro is not exactly overwritten, but another output option is added here:

nitroConfig.rollupConfig.output.sourcemap = true;

Unsure what exactly happens next, but it seems like since the sourceMappingURL reference exist, Nuxt will add them in the route table (or const assets) in .output\server\chunks\runtime.mjs.

If we then decide to remove or exclude the sourcemap-files from the release, it causes some issues when e.g. inspecting the JS-files in browser dev tools since this will cause it to try to request the referenced sourcemap-URL. Since the file does not exist on the server, the runtime throws a nasty ENOENT: no such file or directory, open '/home/site/wwwroot/.output/public/_nuxt/filename.js.map'.

Perhaps a solution would be to first check if the user has already set the sourcemaps options and respect them before setting them to true?

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

@rymdkapten thanks for investigating. We'll discuss an approach forward wrt to forcing sourcemap creation to true. I personally think hidden is a better default, but we'll discuss respecting user settings fully.

@rymdkapten
Copy link

@andreiborza No worries, I just hope it helps! I do agree that hidden seem to be a better default.

@Lms24
Copy link
Member

Lms24 commented Oct 16, 2024

Hey everyone, we discussed this internally today and opened #13993 to track how we will generate source maps going forward. TL;DR: We'll no longer override explicitly disabled source maps. If no source map generation option is set, we'll enable hidden source maps and delete them afterwards.

@s1gr1d
Copy link
Member

s1gr1d commented Oct 18, 2024

Closing this as this was fixed in this PR: #14020

Feel free to re-open this issue if you are experiencing problems. This will be released with 8.35.0

@s1gr1d s1gr1d closed this as completed Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nuxt Issues related to the Sentry Nuxt SDK
Projects
Archived in project
Development

No branches or pull requests

8 participants