It states in the docs that you can’t define the task that way:
TaskManager.defineTask(taskName, task)
Defines task function. It must be called in the global scope of your JavaScript bundle. In particular, it cannot be called in any of React lifecycle methods like componentDidMount . This limitation is due to the fact that when the application is launched in the background, we need to spin up your JavaScript app, run your task and then shut down — no views are mounted in this scenario.
Yo have to define it in another place, but to be honest, I haven’t been able to use the background fecth either, looking at the examples, the define task part shuld be outside of any class or componen, but it doesn’s seem to execute that code. Hope we can find the reason soon.