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 esbuild plugin #1260

Open
ex0ns opened this issue Dec 13, 2024 · 1 comment
Open

Sentry esbuild plugin #1260

ex0ns opened this issue Dec 13, 2024 · 1 comment

Comments

@ex0ns
Copy link

ex0ns commented Dec 13, 2024

Hello

I'm trying to get Sentry's esbuild plugin to work in my setup and I'm struggling to make this work with tsup.
My config is very simple

export default defineConfig({
  entry: ["src/nodeServer.ts"],
  esbuildPlugins: [
    sentryEsbuildPlugin({
      org: "org",
      project: "backend",
      authToken: process.env.SENTRY_AUTH_TOKEN,
      telemetry: false,
      debug: true,
      sourcemaps: {
        assets: "./dist/*",
      },
    }),
  ],
  format: ["esm"],
  // https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/614
  noExternal: ["_sentry-debug-id-injection-stub"],
  env: {
    NODE_ENV: "production",
  },
  dts: false,
  splitting: false,
  sourcemap: true,
  clean: true,
});

I have investigated a bit the issue and summarized everything in this post: getsentry/sentry-javascript-bundler-plugins#614 (comment). I would like to propose a solution but I'm looking for some pointer on where to start and what would be the recommended way of doing this.

My guess is that whenever this plugin's callback is called https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/bd3e31f598f5badaccf011f701d94bbb9e6b6b31/packages/esbuild-plugin/src/index.ts#L232 it then call the common (i.e plugin independent) core function of the plugin, which is looking for file on disk (https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/2.22.5/packages/bundler-plugin-core/src/debug-id-upload.ts#L93). However it seems that whenever we are running the esbuild plugin through tsup, those file are not written on disk yet, and the result of the glob function is always empty.

What would be to correct approach to fix that for tsup ? I would try to stick as close as possible to the esbuild plugin but if not possible I could even rewrite the part of the plugins that do not behave correctly with tsup.

Thanks !

@DaPotatoMan
Copy link

DaPotatoMan commented Dec 18, 2024

@ex0ns This is irrelevant but I was facing the same issue and just went with unbuild.
Here's the sentry usage config:

build.config.ts
import process from 'node:process'
import { sentryRollupPlugin } from '@sentry/rollup-plugin'
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
  entries: ['./src/index'],
  sourcemap: true,
  clean: true,
  externals: [/node_modules/],

  rollup: {
    inlineDependencies: true,
    esbuild: {
      minify: true
    }
  },

  hooks: {
    'rollup:options': (ctx, options) => {
      if (ctx.options.watch)
        return
        
      options.plugins.push(
        sentryRollupPlugin()
      )
    }
  }
})

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

No branches or pull requests

2 participants