question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

undefined is not a constructor (evaluating 'new _expoFirebaseApp.default.links.DynamicLink()

See original GitHub issue

I’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

  1. npm install “expo-firebase-links” (expo-core and expo-firebase-app have been installed in advance)
  2. Follow the Android setup steps on the npm page
  3. 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. 
    );
  }
  1. 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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
aslatterycommented, Mar 11, 2019

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:

W/ReactNativeJS: Possible Unhandled Promise Rejection (id: 0):
    TypeError: undefined is not a constructor (evaluating 'new _expoFirebaseApp.default.links.DynamicLink({REDACTED}, {REDACTED})')
...
0reactions
aslatterycommented, Mar 13, 2019

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

buildscript {
  ...
  dependencies {
    classpath 'com.google.gms:google-services:4.2.0'
    classpath 'com.google.firebase:firebase-plugins:1.1.5'
  }
  ...

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

...
  implementation 'com.google.android.gms:play-services-analytics:16.0.1'
...

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found