'Invariant Violation: Native module cannot be null when implementing React Native Track Player

Today I started learning Expo and React Native and came across an error hen implementing Track Player. The error occurs when I import:

import TrackPlayer from "react-native-track-player";

Before that, I ran

npm install --save react-native-track-player

In my code I haven't coded anything yet, just imported Track Player. Here is the error

Invariant Violation: Native module cannot be null.

Stack trace:
  node_modules\react-native\Libraries\LogBox\LogBox.js:149:8 in registerError
  node_modules\react-native\Libraries\LogBox\LogBox.js:60:8 in errorImpl
  node_modules\react-native\Libraries\LogBox\LogBox.js:34:4 in console.error
  node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
  node_modules\react-native\Libraries\Core\ExceptionsManager.js:104:6 in reportException
  node_modules\react-native\Libraries\Core\ExceptionsManager.js:172:19 in handleException
  node_modules\react-native\Libraries\Core\setUpErrorHandling.js:24:6 in handleError
  node_modules\expo-error-recovery\build\ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0
  node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
  node_modules\regenerator-runtime\runtime.js:294:29 in invoke
  node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
  node_modules\regenerator-runtime\runtime.js:155:27 in invoke
  node_modules\regenerator-runtime\runtime.js:165:18 in PromiseImpl.resolve.then$argument_0
  node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
  node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
  node_modules\react-native\Libraries\Core\Timers\JSTimers.js:123:14 in _callTimer
  node_modules\react-native\Libraries\Core\Timers\JSTimers.js:177:14 in _callImmediatesPass
  node_modules\react-native\Libraries\Core\Timers\JSTimers.js:437:30 in callImmediates
  node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:388:6 in __callImmediates
  node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:132:6 in __guard$argument_0
  node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:365:10 in __guard
  node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:131:4 in flushedQueue
  [native code]:null in flushedQueue
  [native code]:null in invokeCallbackAndReturnFlushedQueue

I am practicing creating an app for IOS on my Windows PC.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source