undefined is not a constructor (evaluating 'new _expoFirebaseApp.default.links.DynamicLink()
See original GitHub issueI’m trying to make an Android app with newly ejected Expokit, but this error happens when I try to use expo-firebase-links.
Thanks!
Environment
System:
OS: macOS 10.14.3
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.12.0 - /usr/local/bin/node
npm: 6.8.0 - /usr/local/bin/npm
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5314842
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
expo: ^32.0.0 => 32.0.6
react: 16.5.0 => 16.5.0
react-native: https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz => 0.57.1
react-navigation: ^3.0.8 => 3.3.2
npmGlobalPackages:
expo-cli: 2.11.6
"expo-core": "^3.0.1",
"expo-firebase-app": "^2.0.0",
"expo-firebase-links": "^2.0.0",
"expokit": "^32.0.7",
Steps to Reproduce
- npm install “expo-firebase-links” (expo-core and expo-firebase-app have been installed in advance)
- Follow the Android setup steps on the npm page
- For Step 4 of the expo-firebase-links setup, add the code below to exponent/MainApplication.java
(The instruction tells you to put those packages in MainActivity, but in expokit 32.0.7 getPackages() in MainActivity returns
((MainApplication) getApplication()).getExpoPackages();
which should refer to the same named method in MainApplication.java)
import expo.modules.firebase.app.FirebaseAppPackage;
import expo.modules.firebase.links.FirebaseLinksPackage;
public List<Package> getExpoPackages() {
return Arrays.<Package>asList(
// other packages
new BackgroundFetchPackage(),
new FirebaseAppPackage(), // Include this.
new FirebaseLinksPackage() // Include this.
);
}
- Add the function down below anywhere in the app.
import firebase from 'expo-firebase-app';
class Example extends Component {
async componentDidMount(){
await firebase.initializeApp({
//insert the whole google-services.json object here
})
}
}
async _handleSubmit(values){
console.log(firebase.links)
const link = new firebase.links.DynamicLink(
'https://example.com',
'https://example.page.link'
).android
.setPackageName('com.example');
console.log(link)
try {
// Create a url that you can share with others.
const url = await firebase.links().createDynamicLink(link);
console.log(url)
} catch ({ message }) {
// An Error was thrown.
console.warn(message);
}
}
}
Expected Behavior
A Dynamic Link is supposed to be logged in the console for console.log(link)
Actual Behavior
The error down below occurs.
[Unhandled promise rejection: TypeError: undefined is not a constructor (evaluating ‘new _expoFirebaseApp.default.links.DynamicLink(‘https://example.com’, ‘https://choresharing.page.link’)’)]
Also, if I console.log the imported firebase at Step 4, all the firebase properties are [Function anonymous] like below.
Firebase {
"analytics": [Function anonymous],
"auth": [Function anonymous],
"config": [Function anonymous],
"crash": [Function anonymous],
"crashlytics": [Function anonymous],
"database": [Function anonymous],
"firestore": [Function anonymous],
"functions": [Function anonymous],
"iid": [Function anonymous],
"invites": [Function anonymous],
"links": [Function anonymous],
"messaging": [Function anonymous],
"notifications": [Function anonymous],
"perf": [Function anonymous],
"storage": [Function anonymous],
"utils": [Function anonymous],
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
undefined is not a constructor (evaluating 'new _auth ...
I'm trying to implement Firebase phone auth in expo. Firebase is connected but its giving me error undefined is ...
Read more >Manually constructing a Dynamic Link URL - Firebase
When users open a Dynamic Link on a desktop web browser, they will load this URL (unless the ofl parameter is specified). If...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Also experiencing this issue while adding an invite link mechanism on Android (haven’t pushed it over to a Mac for testing), where target and base are constants (validated by logs):
Unhandled promise rejection: TypeError: undefined is not a constructor (evaluating 'new_expoFirebaseApp.default.links.DynamicLink(target, base)')
Currently have
"expo-firebase-links": "^2.0.0"
in my packages.Via logcat in Android Studio:
Thanks for confirming it as a known issue. Hope to see these modules make it forward in the future, but totally understand the need to re-prioritize and allocate resources to other more pressing endeavors.
Thought I’d share a few configuration items that allowed me to build RNFirebase 5.2.3 with Expo SDK 32 in Android Studio, as this was a PITA to get working after removing the
expo-firebase-*
modules, and linking in RNFirebase.Using these versions helped resolve a few issues:
android/build.gradle
Following the RNFirebase docs for 5.x.x, add the implementations to your app’s
build.gradle
as necessary. As these use a different version of Google Play Services than previous releases, we need to resolve one of Expokit’s dependencies:android/app/build.gradle
Upgrading this to
16.0.6
resolved mismatched Google Play Services errors at the time of build. A good number of StackOverflow answers regarding this type of error recommended doing various configuration changes, but were only applicable for older versions of the gradle build tools than I was using/ejecting from Expo SDK 32 called for.Be sure to File > Invalidate Caches / Restart as necessary.