amplify-js: Error: evaluating 'global.TYPED_ARRAY_SUPPORT'

Do you want to request a feature or report a bug?

  • a bug.

What is the current behavior?

  • when I just do this: import Amplify from 'aws-amplify'; everything crashes and throws the following error:
05-08 09:53:31.345  6995  7117 E ReactNativeJS: undefined is not an object (evaluating 'global.TYPED_ARRAY_SUPPORT')

05-08 09:53:31.363  6995  7117 W ReactNativeJS: Unable to symbolicate stack trace: undefined is not an object (evaluating 'self.fetch')
05-08 09:53:31.364  6995  7117 E ReactNativeJS: Module AppRegistry is not a registered callable module (calling runApplication)
05-08 09:53:31.365  6995  7117 E ReactNativeJS: Requiring module "fetch", which threw an exception: TypeError: undefined is not an object (evaluating 'self.fetch')
05-08 09:53:31.367  6995  7117 W ReactNativeJS: Unable to symbolicate stack trace: Requiring module "fetch", which threw an exception: TypeError: undefined is not an object (evaluating 'self.fetch')
05-08 09:53:31.367  6995  7117 W ReactNativeJS: Unable to symbolicate stack trace: undefined is not an object (evaluating '_require2(_dependencyMap[0], 'fetch').fetch')

Here is a screenshot: error_screenshot

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than AWS Amplify.

  • I did include my aws ressources as descriped in the docs with just one exceptions: I did remove the RNPushNotificationPackage from my build as I do not need it.

  • Like I said above, all I’ve done was just use this piece of code in my App.js: import Amplify from 'aws-amplify';

  • Step by Step what I’ve done so far:

  1. included these dependencies in my package.json:
"dependencies": {
    "aws-amplify": "^0.3.3",
    "aws-amplify-react-native": "^0.2.9",
    "moment": "^2.22.0",
    "prop-types": "^15.6.1",
    "react": "16.3.2",
    "react-native": "0.55.3",
    "react-native-check-box": "^2.1.0",
    "react-navigation": "^2.0.0",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "amazon-cognito-identity-js": "^2.0.0",
    "aws-sdk": "2.234.1",
    "buffer": "^5.0.7",
    "mime-type": "^3.0.5",
    "path": "^0.12.7",
    "react-devtools": "^3.2.1",
    "react-native-elements": "^0.19.1",
    "react-native-fetch-blob": "^0.10.8",
    "react-native-prompt": "^1.0.0",
    "react-native-uuid": "^1.4.9",
    "react-native-vector-icons": "^4.3.0"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-jest": "22.4.3",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-react-native": "4.0.0",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-config-react-native": "^2.0.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.7.0",
    "eslint-plugin-react-native": "^3.2.1",
    "flow-bin": "^0.71.0",
    "react-native-cli": "^2.0.1",
    "jest": "22.4.3",
    "react-test-renderer": "16.3.2"
  }
  1. Used react-native link, to link all needed parts in android and ios.
  2. Removed aws-amplify from: android\build.gradle, android\settings.gradle, android\app\build.gradle
  3. Removed RNPushNotificationPackage from: android\app\src\main\java\com\appname\MainApplication.java
  4. cd android\ && gradlew clean results:
Incremental java compilation is an incubating feature.
:amazon-cognito-identity-js:clean
:app:clean
:react-native-fetch-blob:clean
:react-native-vector-icons:clean

BUILD SUCCESSFUL

Total time: 11.577 secs
  1. cd .. && react-native run-android results in a successful build as well (I spare you guys with the huge output).

What is the expected behavior?

  • that the import works without an error.

Which versions of Amplify, and which browser / OS are affected by this issue? Did this work in previous versions?

  • see in dependencies above
  • I’m on windows
  • I did not try any different versions BUT: The example here: https://github.com/aws-samples/aws-mobile-react-native-starter was working as expected (with "aws-amplify": "^0.2.4"). After some research and the reason that I did not want to inlcude firebase dependencies lead me to remove RNPushNotificationPackage and aws-amplify from the above mentioned files.

You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app.

  • if needed tell me how to do it in react-native.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 27 (4 by maintainers)

Most upvoted comments

Ok, after some testing today I can confirm that Error: evaluating 'global.TYPED_ARRAY_SUPPORT' is 100% caused by babel --presets env in combination with amazon-cognito-identity.js.

I did change this:

{
  "presets": ["env",  "react-native"]
}

To this:

{
  "presets": ["react-native"]
}

Thanks to @AceNorth for confirming this.

Remember to completley rebuild your app and remove all temporary files to be clean:

  1. remove all from C:\Users\Megajin\AppData\Local\Temp.
  2. remove the folder node_modules .
  3. install all packages with npm install --no-optional.
  4. In current windows console: set RNFB_ANDROID_PERMISSIONS=true (this is for the current session so I can link react-native-fetch-blob).
  5. react-native link

I guess the Issue can be closed as resolved @powerful23 @elorzafe

You guys might find this useful too: @paul-doherty @AndrewSouthpaw @michalziolkowski

Ok I found what my problem was. I was excluding node_modules in my tsconfig like below.

"exclude": [
    "node_modules"
  ],

Turns out this doesn’t exclude it. I set my rootDir to force it to exclude node_modules and now all is good

"rootDirs": [ "app" ],

Thanks

@powerful23 @paul-doherty

It is working now for me. I did the following:

  1. remove all files from my C:\Users\Megajin\AppData\Local\Temp.
  2. removed the folder node_modules .
  3. installed all Packaages with npm install --no-optional.
  4. In current windows console: set RNFB_ANDROID_PERMISSIONS=true (this is for the current session so I can link react-native-fetch-blob).
  5. react-native link

Everything works as expected, but I still do not know what the cause was. I recommend everyone having the same issue to follow my steps above and try a clean install of all packages. If the error still occurs try to remove packages one by one and start with your devDependencies.

I should mention that I did a gradle upgrade. I’ll provide my new updated sources for the android folder:

android\gradle\wrapper\gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

android\build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google() // was needed to prevent the 'lib not found error'
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        classpath 'com.google.gms:google-services:3.2.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        google()
    }
}

android\settings.gradle:

rootProject.name = 'YOUR_APP_NAME'
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-firebase'
project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android')
include ':react-native-fetch-blob'
project(':react-native-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fetch-blob/android')
include ':aws-amplify-react-native'
project(':aws-amplify-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/aws-amplify-react-native/android')
include ':amazon-cognito-identity-js'
project(':amazon-cognito-identity-js').projectDir = new File(rootProject.projectDir, '../node_modules/amazon-cognito-identity-js/android')

include ':app'

android\app\build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.appname"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    implementation(project(':react-native-firebase')) {
        transitive = false
    }
    // Firebase dependencies
    implementation "com.google.android.gms:play-services-base:15.0.0"
    implementation "com.google.firebase:firebase-core:15.0.2"
    implementation project(':aws-amplify-react-native')
    implementation project(':amazon-cognito-identity-js')
    implementation project(':react-native-fetch-blob')
    implementation project(':react-native-vector-icons')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:23.0.1"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

android\app\src\main\AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.appname">

  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

  <application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:allowBackup="false" android:theme="@style/AppTheme">
    <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:windowSoftInputMode="adjustResize">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
        <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
      </intent-filter>
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
  </application>

</manifest>

android\app\src\main\java\com\appname\MainActivity.java:

package com.appname;

import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "appname";
    }
}

android\app\src\main\java\com\appname\MainApplication.java:

package com.appname;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.oblador.vectoricons.VectorIconsPackage;
import io.invertase.firebase.RNFirebasePackage;
import com.RNFetchBlob.RNFetchBlobPackage;
import com.amazonaws.amplify.pushnotification.RNPushNotificationPackage;
import com.amazonaws.RNAWSCognitoPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new VectorIconsPackage(),
            new RNFirebasePackage(),
            new RNFetchBlobPackage(),
            new RNPushNotificationPackage(),
            new RNAWSCognitoPackage()
      );
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}