Cannot read property 'LENGTH_LONG' of undefined
gokulkulkarni1987 opened this issue ยท 44 comments
Hi @gokulkulkarni1987, this means that the Snackbar object itself is undefined. Please make sure you've run react-native link react-native-snackbar
successfully, then rebuild your app using react-native run-ios
or react-native run-android
.
Could you try running the example app and see if you spot any differences?
Here's my successful output for react-native link
:
%> react-native link react-native-snackbar
Scanning 552 folders for symlinks in /home/react-native-snackbar/example/node_modules (2ms)
rnpm-install info Android module react-native-snackbar is already linked
rnpm-install info iOS module react-native-snackbar is already linked
The example does work, I check my config with the config in this example and keep you posted.
hi @cooperka thanks it worked. I had issue with react-native version, after updating to latest version it did work. Thanks for your support.
Same problem using react-native 0.48.3 version and react-native-snackbar 0.4.1 version. Not sure how to resolve it as of yet...
Hi @mattferrin, this error generally means the library wasn't linked properly or React Native can't find it. Can you please clear all your caches and try once more? Often something small gets in the way and the only solution is starting over.
Hi @cooperka I have upgraded my react-native version to 0.49.3 and I have started the getting the issue yet again. :(
Please find below the output of link,
sudo react-native link react-native-snackbar
rnpm-install info Android module react-native-snackbar is already linked
rnpm-install info iOS module react-native-snackbar is already linked
react-native: 0.49.3
react-native-snackbar: 0.4.2
please help me out.
Hmm, I upgraded the example app to RN v0.49 and it all still seems to be working for me.
It's likely still a cache issue; try cleaning everything, including Xcode derived data, watchman, and the React Packager. I run into these sorts of issues occasionally, most often because Xcode is storing all sorts of derived data in various places. You can search online for ways of cleaning it up (unfortunately it's not as simple as just running Clean or deleting your project).
Tried everything, didn't work. But it works in fresh new project. Another one of those instances where the only fix is to create new project and then copy over, install, and link everything from scratch... Not the first time; not the last time.
i'm having this issue when i'm running the tests. i've done everything but nothing seems to work.
i'm on the last version of react-native (v0.50)
pls help
By the way, I created a new project and copied everything over, installed, and linked everything from scratch. It didn't work :) haha.
i got this error on IOS only
"react": "^16.2.0",
"react-native": "^0.52.0"
I linked the package
$react-native link react-native-snackbar
Scanning folders for symlinks in ........../node_modules (31ms)
rnpm-install info Android module react-native-snackbar is already linked
rnpm-install info iOS module react-native-snackbar is already linked
If i import Snackbar from 'react-native-snackbar';
i get the same error
Cannot read property 'LENGTH_LONG' of undefined
Hmm, it looks like linking must have failed somehow even though it says it worked. This seems to happen to some people; try the manual linking solution here: #29 (comment)
thanks @cooperka manually link remove the error ( https://facebook.github.io/react-native/docs/linking-libraries-ios.html )
Hi @emersonmoura, have you tried manually linking?
Hi @cooperka,
Yes...
I checked each file and the "link" was correct
Any hints of the exact reason? This way I can investigate better.
Hmm, it's strange that it says "unmet peer dependency react-native@0.51.0" in your second screenshot. This lib requires >=0.40
so it's definitely satisfied.
Have you tried installing with Yarn instead of npm?
I also found it strange...
Yes, I tried with Yarn. Result: Same red screen
As a last resort, you could try starting with the official example app and progressively make it similar to your own app and see where it breaks.
It could very well be related to your OS. If the example app doesn't work, something larger is likely wrong. Please post back if you find a solution!
I had this issue on Android and did the following to solve it:
- Linked the Snackbar
react-native link react-native-snackbar
- Changed the distributionUrl in the file
android/gradle/wrapper/gradle-wrapper.properties
into:https\://services.gradle.org/distributions/gradle-4.4-all.zip
- Changed the buildscript dependency in the file
android/build.gradle
into:classpath 'com.android.tools.build:gradle:3.1.3
- Executed
react-native run-android
and voila - it worked! ๐
I got the same issue on iOS. I already linked it manually
(https://facebook.github.io/react-native/docs/linking-libraries-ios.html).
But still got the error.
@itanhduy If you are using Pods. Go to ios folder then pod install.
^^ this should definitely go into README. Thanks for pointing out.
The manual installation guide is here, linked from the README. Feel free to edit the wiki if it needs improvement! Thanks.
After adding RNSnackBar.xcproj to Xcode (I recommend doing that manually instead of pod install), go to your app target -> Build Phrases -> Link Binary with Libraries and select RNSnackBar.a
woah, this bug is a nightmare, these devs should apologize. tried a lot of stuff, but no thanks, abort mission!
@masterkrang I spent the last day trying to add this component to my app and couldnt do it. Today I decided to try once more and was able to add it (my app is ios only). Those were my steps:
- Add
pod 'React', :path => '../node_modules/react-native'
to the beginning of my Podfile npm i --save react-native-snackbar
react-native link react-native-snackbar
- (Obviously optional) Fixed wrong indentation in my podfile (happened during link)
cd ios/ && pod install
- Tried to
react-native run-ios
-> failed - Tried to build using Xcode -> failed:
'folly/Portability.h' file not found
- Added these lines at the end of my Podfile:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "React"
target.remove_from_project
end
end
end
And it worked. Can you try these steps?
You can try on Android
- Step 1: run react-native link react-native-snackbar
- Step 2: open MainApplication in getPackages add new SnackbarPackage() to List
import com.azendoo.reactnativesnackbar.SnackbarPackage;
public class MainApplication extends NavigationApplication {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList( new SnackbarPackage());
}
}
+1
Ok, it turns out that for me the issue was due to not restarting the simulator. :-)
hello! this solution don't work with expo..
Readme says this library doesn't support expo.... hopefully will soon?
Hi @bravadomizzou, it's not that Snackbar doesn't support Expo, it's the opposite -- Expo doesn't support Snackbar. You can eject if you want to use Snackbar, or ask Expo to build it into their set of available native components.
I am facing the same issue.
Getting the same error but in react-native-web only.
manual linking also needs to be documented for iOS in readme,
I did pod install by adding this one pod 'RNSnackbar', :path => '../node_modules/react-native-snackbar/RNSnackbar.podspec'
works like charm for me
Working well with Expo. :)
Snackbar.show({
text: 'Image Downloaded Successfully.',
duration: Snackbar.LENGTH_LONG ---> replace with static duration - '1000',
});
@smitkaswala is there anything else i have to do?
@smitkaswala is there anything else i have to do?
Use another package lmfao