Skip to content

Runtime error rendering to the screen in React Native 0.79 #2569

@mcervantes3

Description

@mcervantes3

Describe the Bug
When using React Native 0.79, the app will render a runtime error that was not there before the library was implemented.

The exact error:

"TypeError: the first argument to setImmediate must be a function"

Steps To Reproduce
Install the library in React Native 0.79 and set up a player. Restart the application and when the app launches see if you get a runtime error.

I was able to find a temporary workaround using the patch package. I replaced the code at line 72 in trackPlayer.ts in node_modules > react-native-track-player > src > trackplayer.ts > registerPlaybackService() with this code block:

export function registerPlaybackService(factory: () => ServiceHandler) {
  if (Platform.OS === 'android') {
    // Registers the headless task
    AppRegistry.registerHeadlessTask('TrackPlayer', factory);
  } else if (Platform.OS === 'web') {
    factory()();
  } else {
    // Initializes and runs the service in the next tick
   setTimeout(() => {
  const service = factory();
  if (typeof service === 'function') {
    service();
  } else {
    console.warn('[TrackPlayer] Playback service factory did not return a function. Logic may be initializing too early.');
  }
}, 0);
  }

React Native version: 0.79.2
react-native-track-player version: 4.1.2

I really don't like the idea of having to make patches in my node_modules. It works, but it feels very wrong.

Has anyone else had this issue and know of any other workarounds?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions