KjellConnelly / react-native-shared-group-preferences

127 stars 57 forks source link

TypeError: Cannot read property 'setItem' of undefined #3

Closed trungkhtn closed 5 years ago

trungkhtn commented 6 years ago

TypeError: Cannot read property 'setItem' of undefined at blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:87762:55 at tryCallTwo (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:3524:7) at doResolve (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:3688:15) at new Promise (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:3547:5) at Function.setItem$ (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:87757:51) at tryCatch (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16751:19) at Generator.invoke [as _invoke] (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16924:24) at Generator.prototype.(anonymous function) [as next] (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16794:23) at tryCatch (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16751:19) at invoke (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16827:22)

react native info:

Environment: OS: macOS High Sierra 10.13.4 Node: 9.8.0 Yarn: 1.5.1 npm: 5.6.0 Watchman: 4.9.0 Xcode: Xcode 9.3 Build version 9E145 Android Studio: 3.1 AI-173.4697961

Packages: (wanted => installed) react: 16.3.1 => 16.3.1 react-native: 0.55.3 => 0.55.3

package.json: "react": "16.3.1", "react-native": "0.55.3", "react-native-shared-group-preferences": "^1.0.6",

trungkhtn commented 6 years ago

help me!!!

KjellConnelly commented 6 years ago

You haven’t given enough of a description to help you. I don’t know what the problem is. You’ve given one vague error message and not even described what you’re trying to do and what you’ve tried/haven’t tried.

Btw: this package works for me for my React Native app on version 0.41. If you look through the logs, you’ll see that this never changed. So if there are conflicts with a newer version of RN, I won’t be able to test it as my codebase is stuck far behind the current version.

MartXXIII commented 6 years ago

You probably didn't link the library through Xcode under build phases! React-native link does not link the library properly so you need to link it under "Link binary with Libraries"! Hope this helps! Cheers

antonkovernik commented 6 years ago

TypeError: Cannot read property 'setItem' of undefined at blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:87762:55 at tryCallTwo (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:3524:7) at doResolve (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:3688:15) at new Promise (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:3547:5) at Function.setItem$ (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:87757:51) at tryCatch (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16751:19) at Generator.invoke [as _invoke] (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16924:24) at Generator.prototype.(anonymous function) [as next] (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16794:23) at tryCatch (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16751:19) at invoke (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16827:22)

react native info:

Environment: OS: macOS High Sierra 10.13.4 Node: 9.8.0 Yarn: 1.5.1 npm: 5.6.0 Watchman: 4.9.0 Xcode: Xcode 9.3 Build version 9E145 Android Studio: 3.1 AI-173.4697961

Packages: (wanted => installed) react: 16.3.1 => 16.3.1 react-native: 0.55.3 => 0.55.3

package.json: "react": "16.3.1", "react-native": "0.55.3", "react-native-shared-group-preferences": "^1.0.6",

TypeError: Cannot read property 'setItem' of undefined at blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:87762:55 at tryCallTwo (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:3524:7) at doResolve (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:3688:15) at new Promise (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:3547:5) at Function.setItem$ (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:87757:51) at tryCatch (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16751:19) at Generator.invoke [as _invoke] (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16924:24) at Generator.prototype.(anonymous function) [as next] (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16794:23) at tryCatch (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16751:19) at invoke (blob:http://localhost:8081/bd2a2115-02cc-483d-ab32-573d0bc91e36:16827:22)

react native info:

Environment: OS: macOS High Sierra 10.13.4 Node: 9.8.0 Yarn: 1.5.1 npm: 5.6.0 Watchman: 4.9.0 Xcode: Xcode 9.3 Build version 9E145 Android Studio: 3.1 AI-173.4697961

Packages: (wanted => installed) react: 16.3.1 => 16.3.1 react-native: 0.55.3 => 0.55.3

package.json: "react": "16.3.1", "react-native": "0.55.3", "react-native-shared-group-preferences": "^1.0.6",

Dude you have to invoke: react-native link react-native-shared-group-preferences

738 commented 5 years ago

@MartXXIII Thanks. It works

In my case, the error happens in today widget extension. TypeError: Cannot read property 'setItem' of undefined

I linked libRNReactNativeSharedGroupPreferences.a library directly in today widget extension TARGETS, then the error disappeared.

sandeepdhobi commented 1 year ago

For me this worked

  1. add podspec file in podfile
target 'ShareExtension' do
    # use_react_native!

    pod 'RNReactNativeSharedGroupPreferences', :path => '../node_modules/react-native-shared-group-preferences'
    pod 'RNShareMenu', :path => '../node_modules/react-native-share-menu'
    # Manually link packages here to keep your extension bundle size minimal
  end
  1. adding Library to build phase to Targets
image