sentry-capacitor icon indicating copy to clipboard operation
sentry-capacitor copied to clipboard

TS2451: Cannot redeclare block-scoped variable

Open matthew2564 opened this issue 3 years ago • 18 comments

Is there an existing issue for this?

  • [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [X] I have reviewed the documentation https://docs.sentry.io/
  • [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/angular

SDK Version

7.16.0

Framework Version

Angular 13.3.11 & Ionic 6.3.2

Link to Sentry event

No response

Steps to Reproduce

Node.js v16.10.x

Typescript 4.5.x

Currently we are using the following versions of Sentry package: "@sentry/angular": "^6.19.7", "@sentry/capacitor": "^0.6.1", "@sentry/tracing": "^6.19.7"

After trying to bump all packages to latest i.e.: "@sentry/angular": "^7.16.0", "@sentry/capacitor": "^0.10.1", "@sentry/tracing": "^7.16.0"

Expected Result

No error

Actual Result

I receive the following error:

Error: node_modules/@sentry/types/types/globals.d.ts:2:11 - error TS2451: Cannot redeclare block-scoped variable '__DEBUG_BUILD__'.

2     const __DEBUG_BUILD__: boolean;
            ~~~~~~~~~~~~~~~

  node_modules/@sentry/tracing/node_modules/@sentry/types/types/globals.d.ts:2:11
    2     const __DEBUG_BUILD__: boolean;
                ~~~~~~~~~~~~~~~
    '__DEBUG_BUILD__' was also declared here.

matthew2564 avatar Oct 24 '22 10:10 matthew2564

To fix this you must use a fixed sibling version of angular and tracing

"@sentry/angular": "7.13.0",
"@sentry/capacitor": "0.10.1",
"@sentry/tracing": "7.13.0"

Additionally, at the moment the SDK is compatible with version 7.13.0.

Hopefully this situation will get clearer on the next versions of Sentry Capacitor

lucas-zimerman avatar Oct 25 '22 01:10 lucas-zimerman

By the way, what if when updating the Sentry packages you would get a message like this

This version of Sentry Capacitor is incompatible with the following installed packages:
@sentry/angular version 7.13.0
@sentry/vue version 7.13.0
Please install the mentioned packages with exactly with version 7.15.0 using the below command.
yarn add --exact @sentry/[email protected] @sentry/[email protected] 

Would that be a convenient way of telling you what to do in order to update those packages? (also a similar message if you were using npm for package management)

Ideally it should work out of the box, but unfortunately, it's how the SDK behaves when there's a duplicated sibling package.

lucas-zimerman avatar Oct 25 '22 13:10 lucas-zimerman

I am backlogging this for the JS SDK team because I'd like to fix this more sustainably. Right now we're polluting the global typescript namespace with the JS SDK.

Here is the origin of the problem: https://github.com/getsentry/sentry-javascript/pull/5155#discussion_r885655812 (Note to self: What looks fishy, probably is)

lforst avatar Oct 25 '22 14:10 lforst

Just to let you know, fixing the versions as specified above does work - thank you @lucas-zimerman.

matthew2564 avatar Oct 27 '22 10:10 matthew2564

Had a very similar issue. I was using @sentry/electron 4.1.2 and realized it was relying on @sentry/types 7.16.0 under the hood. After I explicitly added @sentry/types 7.16.0 to my packages.json it worked like a charm.

lnovelli avatar Nov 25 '22 22:11 lnovelli

npm install --save-exact @sentry/[email protected] --update-sentry-capacitor

iborschca avatar Feb 17 '23 23:02 iborschca

Is it only compatible with 7.13.0 or 7.13.0 and later? I'm having trouble with my node modules @sentry/types being 7.31.0.

Click to expand logs
node_modules/@sentry/types/types/globals.d.ts:2:11 - error TS2451: Cannot redeclare block-scoped variable '__DEBUG_BUILD__'.

2     const __DEBUG_BUILD__: boolean;
            ~~~~~~~~~~~~~~~

  node_modules/pino-sentry-breadcrumbs/node_modules/@sentry/types/types/globals.d.ts:2:11
    2     const __DEBUG_BUILD__: boolean;
                ~~~~~~~~~~~~~~~
    '__DEBUG_BUILD__' was also declared here.

node_modules/pino-sentry-breadcrumbs/node_modules/@sentry/types/types/globals.d.ts:2:11 - error TS2451: Cannot redeclare block-scoped variable '__DEBUG_BUILD__'.

2     const __DEBUG_BUILD__: boolean;
            ~~~~~~~~~~~~~~~

  node_modules/@sentry/types/types/globals.d.ts:2:11
    2     const __DEBUG_BUILD__: boolean;
                ~~~~~~~~~~~~~~~
    '__DEBUG_BUILD__' was also declared here.


Found 2 errors in 2 files.

Errors  Files
     1  node_modules/@sentry/types/types/globals.d.ts:2
     1  node_modules/pino-sentry-breadcrumbs/node_modules/@sentry/types/types/globals.d.ts:2

Lilja avatar Feb 28 '23 15:02 Lilja

To fix this right now all versions of the sentry packages should be aligned. So if you're on 7.13.0 you need @sentry/types to be on 7.31.0.

lforst avatar Mar 01 '23 09:03 lforst

Getting same/similar build error on a Ionic 6 / Angular 16 / Capacitor 4 project. Trying to move from @sentry/angular to @sentry/angular-ivy. Dependencies used: "@sentry/angular-ivy": "^7.51.2" "@sentry/capacitor": "^0.11.3"

[ng] Error: node_modules/@sentry/capacitor/node_modules/@sentry/types/types/globals.d.ts:2:11 - error TS2451: Cannot redeclare block-scoped variable '__DEBUG_BUILD__'.
[ng]
[ng] 2     const __DEBUG_BUILD__: boolean;
[ng]             ~~~~~~~~~~~~~~~
[ng]
[ng]   node_modules/@sentry/types/types/globals.d.ts:2:11
[ng]     2     const __DEBUG_BUILD__: boolean;
[ng]                 ~~~~~~~~~~~~~~~
[ng]     '__DEBUG_BUILD__' was also declared here.
[ng]
[ng]
[ng] Error: node_modules/@sentry/types/types/globals.d.ts:2:11 - error TS2451: Cannot redeclare block-scoped variable '__DEBUG_BUILD__'.
[ng]
[ng] 2     const __DEBUG_BUILD__: boolean;
[ng]             ~~~~~~~~~~~~~~~
[ng]
[ng]   node_modules/@sentry/capacitor/node_modules/@sentry/types/types/globals.d.ts:2:11
[ng]     2     const __DEBUG_BUILD__: boolean;
[ng]                 ~~~~~~~~~~~~~~~
[ng]     '__DEBUG_BUILD__' was also declared here.

zarko-tg avatar May 08 '23 23:05 zarko-tg

@zarko-tg If you use @sentry/capacitor v0.11.3 you can't use the latest @sentry/angular-ivy version. The version of @sentry/angular-ivy must match the version used by the @sentry/capacitor library, so in this case 7.50.0. Se also the release notes: https://github.com/getsentry/sentry-capacitor/releases/tag/0.11.3.

houuuuuuuba avatar May 11 '23 13:05 houuuuuuuba

@chutzemischt I think the problem is that support for Angular 16 comes only with 7.51.0.

zarko-tg avatar May 11 '23 13:05 zarko-tg

@zarko-tg zarko-tg

You're right, Angular 16 support comes officially with 7.51.0. Didn't saw that. I've a project which is running with Angular 16 and following versions of sentry:

"@sentry/angular-ivy": "7.50.0" "@sentry/capacitor": "0.11.3"

Of course the legacy-peer-deps has to be set to true.

houuuuuuuba avatar May 11 '23 14:05 houuuuuuuba

This is still a problem, so I opened a new case: https://github.com/getsentry/sentry-capacitor/issues/394

zarko-tg avatar Jun 22 '23 11:06 zarko-tg

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 🥀

github-actions[bot] avatar Jul 14 '23 00:07 github-actions[bot]

I just hit this problem, Angular 15, build was working fine last I touched this, just changed some unrelated files (outside the SPA) and CI is broken but build locally. Sentry 7.81.1

error TS2451: Cannot redeclare block-scoped variable 'DEBUG_BUILD'.

https://github.com/dotnet/nuget-trends/actions/runs/6990848438/job/19020769563?pr=245

I'm using "@sentry-internal/feedback": "0.0.1-alpha.13", (it's not a capacitor app sorry to pile on this issue)

Any tips how to resolve this? (For now I removed the feedback package)

bruno-garcia avatar Nov 25 '23 19:11 bruno-garcia

@bruno-garcia We can fix this upstream. I'll start working on it today!

lforst avatar Nov 27 '23 09:11 lforst

@lucas-zimerman @bruno-garcia We fixed this upstream in the latest JS SDK release so once we update everything this error should be gone for good.

lforst avatar Nov 28 '23 11:11 lforst

Thanks Luca! I'll test it on nuget trends the weekend

bruno-garcia avatar Nov 28 '23 18:11 bruno-garcia

The latest Capacitor already points to the JavaScript SDK with the required fix for this so I am closing this issue, if there are any questions, feel free to create a new issue.

lucas-zimerman avatar Jul 30 '24 22:07 lucas-zimerman