Skip to content

Browser lib contains variable "chrome" that conflicts with the global "chrome" variable #6880

Closed

Description

@wesleyyee

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/browser

SDK Version

7.31.1

Framework Version

No response

Link to Sentry event

No response

SDK Setup

import * as Sentry from '@sentry/browser';
import { BrowserTracing } from '@sentry/tracing';

Sentry.init({
dsn: SENTRY_DSN,
integrations: [new BrowserTracing()],

// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: isProduction ? 0.5 : 1.0,
});

Steps to Reproduce

  • Import sentry into script
  • Load script in browser

Expected Result

No conflicting variable

Actual Result

Uncaught SyntaxError: Identifier 'chrome' has already been declared

Activity

  1. changed the title [-]Browser lib contains variable chrome that conflicts with the global chrome variable[/-] [+]Browser lib contains variable "chrome" that conflicts with the global "chrome" variable[/+] on Jan 19, 2023
  2. AbhiPrasad commented on Jan 19, 2023

    @AbhiPrasad
    Contributor

    Hey @wesleyyee, thanks for writing in. I tried to reproduce this, but was unable to: https://codesandbox.io/s/global-chrome-variable-config-jpu1bm?file=/src/index.js. Could you give some details about how you are bundling you application, and what your bundler config looks like?

    It would be great if you could provide a reproduction of this issue to help us debug further.

  3. wesleyyee commented on Jan 19, 2023

    @wesleyyee
    Author

    Thanks @AbhiPrasad we are using rollup to bundle and the config looks like

    
    export default {
      input: 'barcart/index.js',
      output: {
        file: 'barcart/dist/barcart.js',
        format: 'es',
      },
      plugins: [nodeResolve({ browser: true })],
    };
    
  4. wesleyyee commented on Jan 19, 2023

    @wesleyyee
    Author

    this seems to be the variable that collides with the global chrome object
    https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/stack-parsers.ts#L37

  5. AbhiPrasad commented on Jan 19, 2023

    @AbhiPrasad
    Contributor

    The chrome declaration is not being exported, so I don't know how it ends up in your final bundle since the bundler should be isolating it to it's own lexical scope. I think there is something weird happening with your final bundle that gets generated, maybe it's something to do with nodeResolve?

    Maybe you have to dedupe your sentry imports if there are duplicates appearing?

    From looking around I can only see UI5/webcomponents#4978 which hit a similar problem (also with rollup).

    Do you know what else in your app could be declaring a global chrome object? If you can probably find this by searching through your final generated bundle.

  6. github-actions commented on Feb 10, 2023

    @github-actions
    Contributor

    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 🥀

  7. dmajkic commented on Feb 29, 2024

    @dmajkic

    Could you please review link from @wesleyyee where chrome: is defined. We also had issue with Vite option that disables identifier minification that raised "chrome" conflict with global chrome variable

  8. mydea commented on Feb 29, 2024

    @mydea
    Member

    This link: https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/stack-parsers.ts#L37 does not lead to anything chrome related anymore. If you're still seeing an issue, could you open a new issue with as much info as possible, so we can take a look at reproducing/fixing the issue? thank you!

  9. dmajkic commented on Feb 29, 2024

    @dmajkic

    Line 61:
    https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/stack-parsers.ts#L61

    This was from logs: processed js received on browser side, where we got error:
    image

  10. AbhiPrasad commented on Mar 1, 2024

    @AbhiPrasad
    Contributor

    This is breaking my brain a little bit, but to unblock I opened #10874 - but I think that is not the long term solution.

    We also had issue with Vite option that disables identifier minification that raised "chrome" conflict with global chrome variable

    @dmajkic mind elaborating why you're doing this? It does increase bundle size substantially.

  11. AbhiPrasad commented on Mar 8, 2024

    @AbhiPrasad
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions