Clad Clad
Clad Clad

Reputation: 2771

React Native - Fetch is not a function. Fetch is undefined

I am having a very odd issue recently with one of my project, in one of my page I use a fetch in order to get a file from internet and use the result. But for some reason on both ios and android if I am in debug mode it works but if I leave the debug it gives me a crash.

Debug :

Activate debug Stop debug

I was using react-native 0.53.0 so I tried upgrading to 0.53.3 and now 0.54.4 and it gives me the same result.

 fetch('http://www.podcast411.com/new_demo_feed.xml')
  .then(response => response.text())
  .then((response) => {
      console.log("Parsing", response)
  }).catch((err) => {
    console.log('fetch', err)
  })

For configuration I use :

"npm": "^5.8.0",
"react": "^16.3.0-alpha.1",
"react-native": "0.54.4",
...(lots more librairies)...
"devDependencies": {
    "babel-jest": "22.2.2",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.2.2",
    "react-test-renderer": "16.2.0"
  },

Thanks for your help

IOS Error

Upvotes: 0

Views: 941

Answers (1)

Clad Clad
Clad Clad

Reputation: 2771

This was found by my colleague the problem was that in some part of my code I was assigning this to a var

var self = this

and not releasing it which seems to make (even in another view) the normally available this.fetch unavailable.

So after removing all the assignation the bug is gone... Hope it will help some of you too

Upvotes: 1

Related Questions