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

Esbuild Javascript bundle replaced by a small sentry script #362

Open
dragoon opened this issue Aug 3, 2023 · 10 comments
Open

Esbuild Javascript bundle replaced by a small sentry script #362

dragoon opened this issue Aug 3, 2023 · 10 comments
Labels
bug Something isn't working Status: Stale

Comments

@dragoon
Copy link

dragoon commented Aug 3, 2023

Environment

"@sentry/esbuild-plugin": "^2.5.0",
"esbuild": "^0.18.17",

Steps to Reproduce

Here is my build script

import { build } from 'esbuild';
import  { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";

const devMode = (process.env.NODE_ENV === 'development');
console.log(`${devMode ? 'development' : 'production'} mode bundle`);

// Initialize an empty array for plugins
const plugins = [];

// If not in devMode, add the Sentry plugin
if (!devMode) {
    plugins.push(sentryEsbuildPlugin({
        org: "XXX",
        project: "XXX",
        disable: false,
        authToken: process.env.SENTRY_AUTH_TOKEN,
        sourcemaps: {
            deleteFilesAfterUpload: 'dist/**/*.map',
        },
    }));
}

const base = {
    bundle: true,
    sourcemap: devMode,
    target: ['edge100', 'firefox100', 'chrome87', 'safari15'],
    minify: !devMode,
    entryNames: '[dir]/[name]-[hash]',
    outdir: 'dist',
    plugins: plugins,
    format: "esm"
};

async function buildAndMinify(entryPoint, outDir, target) {
    await build({
        ...base,
        entryPoints: [entryPoint],
        write: true,
        outdir: `dist/${outDir}`,
        target: target || base.target, // use provided target, or default to base.target if no target is provided
    });
}

buildAndMinify('src/index.js', '.').catch(() => process.exit(1));

Expected Result

My actual bundle is generated.

Actual Result

Instead of my usual index.js bundle, here is the script that was generated with sentry esbuild plugin enabled:

var f = (e, d) => () => (e && (d = e(e = 0)), d);
var a, n = f(() => {
    a = typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
    a.SENTRY_RELEASE = {id: "XXXX"}
});
n();
n();
(function () {
    try {
        var e = typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {},
            d = new Error().stack;
        d && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[d] = "XXXX", e._sentryDebugIdIdentifier = "sentry-dbid-XXXX")
    } catch {
    }
})();
var r = void 0;
export {r as default};

I have no idea what is this script, but my usual bundle is nowhere to be found.

@lforst
Copy link
Member

lforst commented Aug 3, 2023

Hi, thanks for writing in. Unfortunately, I cannot reproduce your issue. Would you mind sharing a Stackblitz or a repo we could pull to reproduce this? Thanks!

@dragoon
Copy link
Author

dragoon commented Aug 3, 2023

Thank you for the quick reply. I cannot share the repo unfortunately, I will try to create a sample repo or a stackblitz

@lforst lforst added bug Something isn't working Waiting for: Community labels Aug 11, 2023
@getsantry getsantry bot moved this to Waiting for: Community in GitHub Issues with 👀 Aug 17, 2023
@github-actions
Copy link

github-actions bot commented Sep 8, 2023

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@mydea mydea closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2023
@jam-fran
Copy link

jam-fran commented Mar 5, 2024

@dragoon Do you remember if this issue was resolved, and if so, how you did it? Coming across the same thing and I'm stumped.

@lforst
Copy link
Member

lforst commented Mar 5, 2024

This issue was closed due to inactivity. We need reproduction of this issue to be able to resolve it!

@dragoon
Copy link
Author

dragoon commented Mar 5, 2024

@jam-fran no, I wasn't able to solve it, just not shipping source maps to sentry at the moment. I didn't have time to create a reproducible repo so far.

@jam-fran
Copy link

jam-fran commented Mar 5, 2024

@lforst I was working on a sample repo when I discovered this appears to be related to #471 -- when I added a default export to my app.ts file it worked as expected.

Before:

const app = express()

Sentry.init({
  dsn: env.SENTRY_DSN,
  environment: env.APP_ENV,
  release: env.SENTRY_RELEASE,
})

app.use(Sentry.Handlers.requestHandler())

// Controllers

app.use(Sentry.Handlers.errorHandler())

app.listen(env.PORT, () => {
  console.log(`📡 Server started on port ${env.PORT}`)
})

After:

const app = express()

Sentry.init({
  dsn: env.SENTRY_DSN,
  environment: env.APP_ENV,
  release: env.SENTRY_RELEASE,
})

app.use(Sentry.Handlers.requestHandler())

// Controllers

app.use(Sentry.Handlers.errorHandler())

app.listen(env.PORT, () => {
  console.log(`📡 Server started on port ${env.PORT}`)
})

export default app

@dragoon
Copy link
Author

dragoon commented Mar 5, 2024

Great to know @jam-fran, it works indeed, I don't use any framework, my entry point is a plain javascript file, when I add export default somefunction, js file is generated correctly.

@lforst
Copy link
Member

lforst commented Mar 5, 2024

That is odd... Maybe we can fix this somehow.

@codybrouwers
Copy link

Also ran into this with @sentry/esbuild-plugin, Sentry replaced my entire script file with:

import { createRequire as _createRequire } from "module"
const require = _createRequire(import.meta.url)
var n =
  typeof window < "u"
    ? window
    : typeof global < "u"
    ? global
    : typeof self < "u"
    ? self
    : {}
n.SENTRY_RELEASE = { id: "x" }
;(function () {
  try {
    var e =
        typeof window < "u"
          ? window
          : typeof global < "u"
          ? global
          : typeof self < "u"
          ? self
          : {},
      d = new Error().stack
    d &&
      ((e._sentryDebugIds = e._sentryDebugIds || {}),
      (e._sentryDebugIds[d] = "x"),
      (e._sentryDebugIdIdentifier =
        "sentry-dbid-x"))
  } catch {}
})()
var b = void 0
export { b as default }

Adding an export to the file, even though I don't need it, fixed the issue. This was a tough one to debug 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Status: Stale
Projects
Archived in project
Status: No status
Status: No status
Development

No branches or pull requests

5 participants