expo / browser-polyfill

Browser polyfill for making React Native compatible with web libs like pixi.js, three.js, phaser.js
MIT License
61 stars 23 forks source link

Receiving error on android (com.facebook.react.bridge.ReadableNativeMap cannot be cast to java.lang.Strin) #10

Open jm90m opened 6 years ago

jm90m commented 6 years ago

I am currently working on a new cryptocurrency / chat mobile app using matrix sdk (https://github.com/matrix-org/matrix-js-sdk), and this fails for me on android, I receive the com.facebook.react.bridge.ReadableNativeMap cannot be cast to java.lang.String error.

screen shot 2018-08-23 at 4 43 10 pm

How to reproduce

Current Solution

Right now I have a file called polyfill.js and I import it only for android within App.js - contents of this file were taken from Node.js file in this library, credit goes to @EvanBacon

import { EventEmitter } from 'fbemitter';

class Document {
  constructor() {
    this.emitter = new EventEmitter();
    this.addEventListener = this.addEventListener.bind(this);
    this.removeEventListener = this.removeEventListener.bind(this);
    this._checkEmitter = this._checkEmitter.bind(this);
  }

  createElement(tagName) {
    return {};
  }

  _checkEmitter() {
    if (
      !this.emitter ||
      !(this.emitter.on || this.emitter.addEventListener || this.emitter.addListener)
    ) {
      this.emitter = new EventEmitter();
    }
  }

  addEventListener(eventName, listener) {
    this._checkEmitter();
    if (this.emitter.on) {
      this.emitter.on(eventName, listener);
    } else if (this.emitter.addEventListener) {
      this.emitter.addEventListener(eventName, listener);
    } else if (this.emitter.addListener) {
      this.emitter.addListener(eventName, listener);
    }
  }

  removeEventListener(eventName, listener) {
    this._checkEmitter();
    if (this.emitter.off) {
      this.emitter.off(eventName, listener);
    } else if (this.emitter.removeEventListener) {
      this.emitter.removeEventListener(eventName, listener);
    } else if (this.emitter.removeListener) {
      this.emitter.removeListener(eventName, listener);
    }
  }
}

window.document = window.document || new Document();
EvanBacon commented 5 years ago

In theory it does work in vanilla React Native but this error seems deeply rooted in GL stuff (normalize is used in a shader that isn't supported on android?). GL is really only supported in Expo, it would take a lot of time to debug this issue but I think just adding Expo will solve your issues.

ashu777 commented 5 years ago

same here. i am getting error: Value for title cannot be cast from ReadableNativeMap to String

Ilario17 commented 5 years ago

did you figure out how to solve?

zelenko commented 4 years ago

In some cases if this error appears it means instead of JS object need to pass a string: JSON.stringify(value).