Uncaught TypeError: t.spanContext is not a function in CDN import
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 SDK are you using?
@sentry/browser
SDK Version
8.34.0
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
No response
Steps to Reproduce
User provided code example but i was unable to reproduce with it on my own setup. There is a public server and the steps to reproduce are available on this internal ticket (contains a login and cant be shared publicly)
Expected Result
No errors from the SDK.
Actual Result
Uncaught TypeError: t.spanContext is not a function in the console. By inspecting the code, it is coming from this line: https://github.com/getsentry/sentry-javascript/blob/develop/packages/core/src/utils/spanUtils.ts#L175
Hmm, i am not quite sure why, but it seems that for whatever reason, on this page Array.from(set) is not behaving as expected. I would guess that something somewhere is incorrectly monkey patching something...
Normally, this code should work:
const set = new Set();
set.add('aa');
set.add('bb');
const array = Array.from(set);
// --> ['aa', 'bb']
However, if I rund this code on the linked site, the output is:
// --> [Set(2)]
So Array.from() is not correctly identifiying the set as iterable. The only reason I can think of for this is some polyfill or monkey patch that is not quite correct. The behavior we rely on is correct, though (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from) so that has to be some problem on the site specifically, I feel...
Would it make sense for some of the code here to be causing the issue? https://github.com/search?q=org%3Amootools+%22array.from+%3D%22&type=code The error appears on pages with that library (mootools)
Hi @mendelgordon that could be the case, is there a way for you to test if the behaviour changes once you exclude this lib?
Once that library is removed, the error disappears, but it causes new errors for the code that relied on the library. I have updated the code and it appears to be functioning properly now.
I believe it would be beneficial if having Sentry and MooTools together did not result in such issues.
You would need to raise this with MooTools then as it seems the function does not behave as expected after their patching. Thanks for pointing this out.
Why was this issue closed?
We appreciate the feedback but unfortunately don't see a clear path to resolve this issue on our Side. In some cases, JS-land is too individual to cover every use case in our SDKs.
Please feel free to leave a comment if you think this issue should be reopened.