React-native-track-player: Cannot read property 'STATE_NONE' of undefined

Created on 27 Nov 2017  路  9Comments  路  Source: react-native-kit/react-native-track-player

I'm getting the following error when trying to import this library:"Cannot read property 'STATE_NONE' of undefined". It appears to be happening in "index.js" at line 94: module.exports.STATE_NONE = TrackPlayer.STATE_NONE;, and TrackPlayer is undefined.

I've tried uninstalling all my modules and reinstalling, and unlinking and linking. Any idea what is going on? This is on iOS by the way.

Most helpful comment

This issue has been fixed on the develop branch but we have not yet published a new version to npm with these fixes. /cc @Guichaguri

All 9 comments

Which version of React Native are you using?
Also, which version of this module are you using?

React Native v0.49.5
[email protected]

I just upgraded react native to v0.50.4, and am getting the same error, but now I'm getting this extra error info in the terminal after I run react-native run-ios:

/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:48:19: error: overriding method with selector 'constantsToExport' has incompatible type '() -> [String : Any]'
    override func constantsToExport() -> [String: Any] {
                  ^
__ObjC.RCTEventEmitter:79:15: note: overridden declaration here has type '() -> [AnyHashable : Any]!'
    open func constantsToExport() -> [AnyHashable : Any]!
              ^
/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:30:22: warning: expression implicitly coerced from 'String?' to Any
            "track": trackId,
                     ^~~~~~~
/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:30:22: note: provide a default value to avoid this warning
            "track": trackId,
                     ^~~~~~~
                             ?? <#default value#>
/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:30:22: note: force-unwrap the value to avoid this warning
            "track": trackId,
                     ^~~~~~~
                            !
/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:30:22: note: explicitly cast to Any with 'as Any' to silence this warning
            "track": trackId,
                     ^~~~~~~
                             as Any
/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:31:25: warning: expression implicitly coerced from 'TimeInterval?' (aka 'Optional<Double>') to Any
            "position": time,
                        ^~~~
/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:31:25: note: provide a default value to avoid this warning
            "position": time,
                        ^~~~
                             ?? <#default value#>
/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:31:25: note: force-unwrap the value to avoid this warning
            "position": time,
                        ^~~~
                            !
/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:31:25: note: explicitly cast to Any with 'as Any' to silence this warning
            "position": time,
                        ^~~~
                             as Any
/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:32:26: warning: expression implicitly coerced from 'String?' to Any
            "nextTrack": nextTrackId
                         ^~~~~~~~~~~
/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:32:26: note: provide a default value to avoid this warning
            "nextTrack": nextTrackId
                         ^~~~~~~~~~~
                                     ?? <#default value#>
/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:32:26: note: force-unwrap the value to avoid this warning
            "nextTrack": nextTrackId
                         ^~~~~~~~~~~
                                    !
/Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift:32:26: note: explicitly cast to Any with 'as Any' to silence this warning
            "nextTrack": nextTrackId
                         ^~~~~~~~~~~
                                     as Any



** BUILD FAILED **


The following build commands failed:

    CompileSwift normal x86_64 /Users/Gurtaj/Dropbox/SocialPodcast/PodcastApp/node_modules/react-native-track-player/ios/RNTrackPlayer/RNTrackPlayer.swift
    CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)

This issue has been fixed on the develop branch but we have not yet published a new version to npm with these fixes. /cc @Guichaguri

Sounds good! Thanks for the response

@Guichaguri Hi, any update on this? I tried the latest version and the dev branch and receive the STATE_NONE error. I am using react-native 0.51.0 and building for iOS. Thanks!

@joserocha3 noticed we had a similar problem. I figured this one out on my own earlier

Not sure if you've done the 'add a .swift file to your project' in the docs but if not then try that step first
1) https://github.com/react-native-kit/react-native-track-player/wiki/Installation#troubleshooting

Second, which after I did that myself I still had an issue - check my comment on this other issue and try manually linking the react-native-track-player library using the steps i posted.
2) https://github.com/react-native-kit/react-native-track-player/issues/96#issuecomment-352440855

Hopefully it works out for you

Had the same problem (RN 0.48, react-native-track-player v0.2.1) and managed to fix this by manually linking the library. You know, the usual- move the .a file to Link Binaries with Library.

I am having this same issue and I have done everything suggested here. I am running a detached expo project, I ran the step-by-step install process as outlined in the API docs, and I added a dummy.swift file and enabled the bridging header option in xCode. Still getting this issue. I am running react-native v0.55.3 react-native-track-player v0.2.4. Any help would be SUPER appreciated.

Was this page helpful?
0 / 5 - 0 ratings