Skip to content

Cannot read property 'then' of undefined (getNativeFetchImplementation) #5792

Closed

Description

@silverWolf818

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.12.1

Framework Version

react 17.0.2

Link to Sentry event

https://sentry.io/organizations/jinshuju/issues/3610808007/?project=1360752

Steps to Reproduce

image

I find source code:

https://github.com/getsentry/sentry-javascript/blob/7.13.0/packages/browser/src/transports/fetch.ts

image

Expected Result

no error

Actual Result

image

Activity

  1. AbhiPrasad commented on Sep 22, 2022

    @AbhiPrasad
    Contributor

    Hey, thanks for writing in!

    For fetch to not be defined, are you monkeypatching or changing the fetch global in any way? We are just grabbing the fetch impl from the possible scope. The error you linked seems to not have any browser info, is that code being run as part of server-side rendering?

  2. changed the title [-]Cannot read property 'then' of undefined[/-] [+]Cannot read property 'then' of undefined (`getNativeFetchImplementation`)[/+] on Oct 14, 2022
  3. AbhiPrasad commented on Oct 17, 2022

    @AbhiPrasad
    Contributor

    Tracking internally in https://www.notion.so/sentry/undefined-nativeFetch-call-347f73dcf0494660910235e286197da6 as we've had a Sentry saas customer report this as well.

  4. self-assigned this
    on Oct 17, 2022
  5. webelart commented on Oct 24, 2022

    @webelart

    Hey, thank you for investigation time into this problem.
    We have the same issue. 284k errors for the last 30 days. How we can help you with information for understanding this problem?

    File which is reported with error -> @senty/browser/types/transports/fetch.d.ts

    We have TypeError. Array.forEach(native)
    Message: Cannot read property 'then' of undefined

    Stack trace

    // webpack://client/../src/transports/fetch.ts in makeRequest at line 33:1
    
     return nativeFetch(options.url, requestOptions).then(response => ({
          statusCode: response.status,
          headers: {
            'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
            'retry-after': response.headers.get('Retry-After'),
          },

    Additional info which connected with this error

    // native in Array.forEach
    // webpack://client/../src/syncpromise.ts in t._executeHandlers at line 176:1
    const cachedHandlers = this._handlers.slice();
        this._handlers = [];
        cachedHandlers.forEach(handler => {
          if (handler[0]) {
            return;
          }
          if (this._state === States.RESOLVED) {
  6. AbhiPrasad commented on Oct 24, 2022

    @AbhiPrasad
    Contributor

    @liveldi are you monkeypatching fetch in anyway? Could you share the Sentry errors where this is happening?

  7. webelart commented on Oct 24, 2022

    @webelart

    @AbhiPrasad Thank you for answering!

    Are you monkeypatching or changing the fetch global in any way?

    We only use @babel/preset-env (7.12.16) & core-js (3.19.3) And for us looks like that when we downgrade these versions the amount of mistakes decreases. But not looks like a permanent decision, because today we have 2200 errors on it.

    Also we don't use transforms. Some screenshots

    Screenshot 2022-10-24 at 17 05 23

  8. AbhiPrasad commented on Oct 25, 2022

    @AbhiPrasad
    Contributor

    @liveldi thanks for getting back! Are you using any 3rd party SDKs that might be mutating/monkeypatching fetch in any way?

  9. AbhiPrasad commented on Oct 25, 2022

    @AbhiPrasad
    Contributor

    For now we are patching this to stop any future errors. Fix will be part of the next release!

  10. webelart commented on Oct 25, 2022

    @webelart

    @AbhiPrasad ok, thank you! For now I didn't find anything in our application which could change native fetch. I only thought maybe transpiler or a side effect from npm library. But found nothing. Looks like we not touch somehow fetch.

  11. AbhiPrasad commented on Oct 25, 2022

    @AbhiPrasad
    Contributor

    @liveldi might be a browser extension here, which we really can't do anything about. Will continue to investigate!

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions