Giter Site home page Giter Site logo

Comments (8)

KevinHu2014 avatar KevinHu2014 commented on May 24, 2024 3

@BMillman19
While using version 2.0.8 on React Native project, we encounter similar issues.
Besides the same issue of isomorphic-fetch.

  1. undefined is not a function

In ./utils/lib/src/abi_encoder/emv_data_type_factory.js

'use strict'
var __extends =
  (this && this.__extends) ||
  (function () {
    var extendStatics = function (d, b) {
      extendStatics =
        Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array &&    //  <-  this line will throw error
          function (d, b) {
            d.__proto__ = b
          }) ||
        function (d, b) {
          for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]
        }
      return extendStatics(d, b)
    }
    return function (d, b) {
      extendStatics(d, b)
      function __ () {
        this.constructor = d
      }
      d.prototype =
        b === null ? Object.create(b) : ((__.prototype = b.prototype), new __())
    }
  })()
...
  1. undefined is not a valid argument for ...

In ./node_modules/chalk/index.js (this seems to be a dependency module)

'use strict';
const escapeStringRegexp = require('escape-string-regexp');
const ansiStyles = require('ansi-styles');
const stdoutColor = require('supports-color').stdout;

const template = require('./templates.js');

const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');

// `supportsColor.level` → `ansiStyles.color[name]` mapping
const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];

// `color-convert` models to exclude from the Chalk API due to conflicts and such
const skipModels = new Set(['gray']);
// Object = global;
const styles = Object.create(null);

function applyOptions(obj, options) {
	options = options || {};

	// Detect level if not set manually
	const scLevel = stdoutColor ? stdoutColor.level : 0;
	obj.level = options.level === undefined ? scLevel : options.level;
	obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
}

function Chalk(options) {
	// We check for this.template here since calling `chalk.constructor()`
	// by itself will have a `this` of a previously constructed chalk object
	if (!this || !(this instanceof Chalk) || this.template) {
		const chalk = {};
		applyOptions(chalk, options);

		chalk.template = function () {
			const args = [].slice.call(arguments);
			return chalkTag.apply(null, [chalk.template].concat(args));
		};
		Object.setPrototypeOf(chalk, Chalk.prototype); // this line throws error
		Object.setPrototypeOf(chalk.template, chalk);

		chalk.template.constructor = Chalk;

		return chalk.template;
	}

	applyOptions(this, options);
}
 ...

Work Around (Hack)

The two error cases above seems to be the same problem.
Caused by Object.setPrototypeOf doesn’t work on JSC on Android.
For now we add polyfill to these places.

Here's the polyfill we use

Object.setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
        obj.__proto__ = proto
        return obj
       }
'use strict'
var __extends =
  (this && this.__extends) ||
  (function () {
    var extendStatics = function (d, b) {
     //  Apply polyfill here
      Object.setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
        obj.__proto__ = proto
        return obj
       }

      extendStatics =
        Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array &&
          function (d, b) {
            d.__proto__ = b
          }) ||
        function (d, b) {
          for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]
        }
      return extendStatics(d, b)
    }
    return function (d, b) {
      extendStatics(d, b)
      function __ () {
        this.constructor = d
      }
      d.prototype =
        b === null ? Object.create(b) : ((__.prototype = b.prototype), new __())
    }
  })()
...
'use strict';
const escapeStringRegexp = require('escape-string-regexp');
const ansiStyles = require('ansi-styles');
const stdoutColor = require('supports-color').stdout;

const template = require('./templates.js');

const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');

// `supportsColor.level` → `ansiStyles.color[name]` mapping
const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];

// `color-convert` models to exclude from the Chalk API due to conflicts and such
const skipModels = new Set(['gray']);
// Object = global;
const styles = Object.create(null);

function applyOptions(obj, options) {
	options = options || {};

	// Detect level if not set manually
	const scLevel = stdoutColor ? stdoutColor.level : 0;
	obj.level = options.level === undefined ? scLevel : options.level;
	obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
}

function Chalk(options) {
	// We check for this.template here since calling `chalk.constructor()`
	// by itself will have a `this` of a previously constructed chalk object
	if (!this || !(this instanceof Chalk) || this.template) {
		const chalk = {};
		applyOptions(chalk, options);

		chalk.template = function () {
			const args = [].slice.call(arguments);
			return chalkTag.apply(null, [chalk.template].concat(args));
		};
                //  Apply polyfill here
		Object.setPrototypeOf = Object.setPrototypeOf || function (obj, proto) { error
			obj.__proto__ = proto
			return obj
		}
		Object.setPrototypeOf(chalk, Chalk.prototype);
		Object.setPrototypeOf(chalk.template, chalk);

		chalk.template.constructor = Chalk;

		return chalk.template;
	}

	applyOptions(this, options);
}
 ...

Discussion

The hacking work around doesn't seems to be a good solution.
@BMillman19 Is there any suggestions ?
I'm willing to help, contribute the react-native support.

from 0x-monorepo.

KevinHu2014 avatar KevinHu2014 commented on May 24, 2024 1

@kylanhurt

Actually it turns out that it may have been related to my simulator not being in debug mode.

This is due to the different run time that React Native is using.
In debug mode, React Native is running on Chrome which uses V8.
While running on physical device , React Native uses JSC(JavaScriptCore).

from 0x-monorepo.

kylanhurt avatar kylanhurt commented on May 24, 2024

This is also causing an issue for me!

from 0x-monorepo.

fabioberger avatar fabioberger commented on May 24, 2024

Hm, what replacement library would you recommend we use such that it works in browsers, node and react-native contexts?

from 0x-monorepo.

kylanhurt avatar kylanhurt commented on May 24, 2024

@fabioberger Actually it turns out that it may have been related to my simulator not being in debug mode. If the issue pops up again I'll do some more diligence. Really is one of the strangest bugs I've ever encountered in React Native.

Thank you for the quick response, though!

from 0x-monorepo.

BMillman19 avatar BMillman19 commented on May 24, 2024

@kylanhurt is connect working for you in react native?

from 0x-monorepo.

kylanhurt avatar kylanhurt commented on May 24, 2024

@BMillman19 It's working. The isometric fetch issue is a nagging issue for many React Native projects (including outside of 0x-related stuff).

I hope people find this issue so that they can see if my solution fixes it for them.

from 0x-monorepo.

stale avatar stale commented on May 24, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from 0x-monorepo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.