a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
atproto bluesky typescript npm

Creating simpleFetchHandler errors out in React Native #8

open opened by sharpmars.nekoweb.org

When I create simpleFetchHandler in React Native it errors out with: [TypeError: Cannot read property 'prototype' of undefined]. Looking at bundled code only mentions of .prototype are in atcute/lexicons/dist/syntax and atcute/client/dist/index.

[deleted by author]

Here's the log, maybe someone knows a bit more

ERROR  [TypeError: Cannot read property 'prototype' of undefined]

Call Stack
  <global> (node_modules\@atcute\lexicons\dist\validations\utils.js)
  loadModuleImplementation (node_modules\@expo\cli\build\metro-require\require.js)
  guardedLoadModule (node_modules\@expo\cli\build\metro-require\require.js)
  metroRequire (node_modules\@expo\cli\build\metro-require\require.js)
  <global> (node_modules\@atcute\lexicons\dist\syntax\uri.js)
  loadModuleImplementation (node_modules\@expo\cli\build\metro-require\require.js)
  guardedLoadModule (node_modules\@expo\cli\build\metro-require\require.js)
  metroRequire (node_modules\@expo\cli\build\metro-require\require.js)
  <global> (node_modules\@atcute\lexicons\dist\syntax\index.js)
  loadModuleImplementation (node_modules\@expo\cli\build\metro-require\require.js)
  guardedLoadModule (node_modules\@expo\cli\build\metro-require\require.js)
  metroRequire (node_modules\@expo\cli\build\metro-require\require.js)
  <global> (node_modules\@atcute\lexicons\dist\validations\index.js)
  loadModuleImplementation (node_modules\@expo\cli\build\metro-require\require.js)
  guardedLoadModule (node_modules\@expo\cli\build\metro-require\require.js)
  metroRequire (node_modules\@expo\cli\build\metro-require\require.js)
  <global> (node_modules\@atcute\client\dist\client.js)
  loadModuleImplementation (node_modules\@expo\cli\build\metro-require\require.js)
  guardedLoadModule (node_modules\@expo\cli\build\metro-require\require.js)
  metroRequire (node_modules\@expo\cli\build\metro-require\require.js)
  <global> (node_modules\@atcute\client\dist\index.js)
  loadModuleImplementation (node_modules\@expo\cli\build\metro-require\require.js)
  guardedLoadModule (node_modules\@expo\cli\build\metro-require\require.js)
  metroRequire (node_modules\@expo\cli\build\metro-require\require.js)
  <global> (app\(tabs)\index.tsx)
  loadModuleImplementation (node_modules\@expo\cli\build\metro-require\require.js)
  guardedLoadModule (node_modules\@expo\cli\build\metro-require\require.js)
  metroRequire (node_modules\@expo\cli\build\metro-require\require.js)
  Object.defineProperties$argument_1.tabsIndexTsx.get (app)
  metroContext (app)
  node.loadRoute (node_modules\expo-router\build\getRoutesCore.js)
  getDirectoryTree (node_modules\expo-router\build\getRoutesCore.js)
  getDirectoryTree (node_modules\expo-router\build\getRoutesCore.js)
  getRoutes (node_modules\expo-router\build\getRoutesCore.js)
  getRoutes (node_modules\expo-router\build\getRoutes.js)
  useStore (node_modules\expo-router\build\global-state\router-store.js)
  ContextNavigator (node_modules\expo-router\build\ExpoRoot.js)
  callComponent.reactStackBottomFrame (node_modules\react-native\Libraries\Renderer\implementations\ReactFabric-dev.js)
  renderWithHooks (node_modules\react-native\Libraries\Renderer\implementations\ReactFabric-dev.js)
  updateFunctionComponent (node_modules\react-native\Libraries\Renderer\implementations\ReactFabric-dev.js)
  beginWork (node_modules\react-native\Libraries\Renderer\implementations\ReactFabric-dev.js)
  runWithFiberInDEV (node_modules\react-native\Libraries\Renderer\implementations\ReactFabric-dev.js)
  performUnitOfWork (node_modules\react-native\Libraries\Renderer\implementations\ReactFabric-dev.js)
  workLoopSync (node_modules\react-native\Libraries\Renderer\implementations\ReactFabric-dev.js)
  renderRootSync (node_modules\react-native\Libraries\Renderer\implementations\ReactFabric-dev.js)
  performWorkOnRoot (node_modules\react-native\Libraries\Renderer\implementations\ReactFabric-dev.js)
  performWorkOnRootViaSchedulerTask (node_modules\react-native\Libraries\Renderer\implementations\ReactFabric-dev.js)

Call Stack
  ExpoRoot (node_modules\expo-router\build\ExpoRoot.js)
  App (node_modules\expo-router\build\qualified-entry.js)
  WithDevTools (node_modules\expo\src\launch\withDevTools.tsx)

blergh annoying, let me try setting up an Expo project later

TypeError: Cannot read property 'prototype' of undefined at anonymous (192.168.1.14:8081/node_modules/%40atcute/lexicons/dist/validations/utils.bundle//&platform=android&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=1&transform.routerRoot=app&transform.reactCompiler=true&unstable_transformProfile=hermes-stable&minify=false&modulesOnly=true&runModule=false&shallow=true:49:37) ...

__d(function (global, require, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {
  "use strict";

  Object.defineProperty(exports, '__esModule', {
    value: true
  });
  Object.defineProperty(exports, "getUtf8Length", {
    enumerable: true,
    get: function () {
      return getUtf8Length;
    }
  });
  Object.defineProperty(exports, "getGraphemeLength", {
    enumerable: true,
    get: function () {
      return getGraphemeLength;
    }
  });
  Object.defineProperty(exports, "lazyProperty", {
    enumerable: true,
    get: function () {
      return lazyProperty;
    }
  });
  Object.defineProperty(exports, "lazy", {
    enumerable: true,
    get: function () {
      return lazy;
    }
  });
  Object.defineProperty(exports, "isArray", {
    enumerable: true,
    get: function () {
      return isArray;
    }
  });
  Object.defineProperty(exports, "isObject", {
    enumerable: true,
    get: function () {
      return isObject;
    }
  });
  Object.defineProperty(exports, "allowsEval", {
    enumerable: true,
    get: function () {
      return allowsEval;
    }
  });
  var segmenter = new Intl.Segmenter();
  var getUtf8Length = str => {
    var len = str.length;
    var u16pos = 0;
    var u8pos = 0;
    jump: if (str.charCodeAt(0) < 0x80) {
      u16pos++;
      u8pos++;
      while (u16pos + 3 < len) {
        var a = str.charCodeAt(u16pos);
        var b = str.charCodeAt(u16pos + 1);
        var c = str.charCodeAt(u16pos + 2);
        var d = str.charCodeAt(u16pos + 3);
        if ((a | b | c | d) >= 0x80) {
          break jump;
        }
        u16pos += 4;
        u8pos += 4;
      }
      while (u16pos < len) {
        var x = str.charCodeAt(u16pos);
        if (x >= 0x80) {
          break jump;
        }
        u16pos++;
        u8pos++;
      }
      return u8pos;
    }
    while (u16pos < len) {
      var code = str.charCodeAt(u16pos);
      if (code < 0x80) {
        u16pos += 1;
        u8pos += 1;
      } else if (code < 0x800) {
        u16pos += 1;
        u8pos += 2;
      } else if (code < 0xd800 || code > 0xdbff) {
        u16pos += 1;
        u8pos += 3;
      } else {
        u16pos += 2;
        u8pos += 4;
      }
    }
    return u8pos;
  };
  var getGraphemeLength = text => {
    var iterator = segmenter.segment(text)[Symbol.iterator]();
    var count = 0;
    while (!iterator.next().done) {
      count++;
    }
    return count;
  };
  // #__NO_SIDE_EFFECTS__
  var lazyProperty = (obj, prop, value) => {
    Object.defineProperty(obj, prop, {
      value
    });
    return value;
  };
  // #__NO_SIDE_EFFECTS__
  var lazy = getter => {
    return {
      get value() {
        var value = getter();
        return lazyProperty(this, 'value', value);
      }
    };
  };
  var isArray = Array.isArray;
  // #__NO_SIDE_EFFECTS__
  var isObject = input => {
    return typeof input === 'object' && input !== null && !isArray(input);
  };
  var allowsEval = /*#__PURE__*/lazy(() => {
    if (typeof navigator !== 'undefined' && navigator?.userAgent?.includes('Cloudflare')) {
      return false;
    }
    try {
      var F = Function;
      new F('');
      return true;
    } catch (_) {
      return false;
    }
  });
},1512,[],"node_modules/@atcute/lexicons/dist/validations/utils.js");
//# sourceMappingURL=http://192.168.1.14:8081/node_modules/%40atcute/lexicons/dist/validations/utils.map?platform=android&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=1&transform.routerRoot=app&transform.reactCompiler=true&unstable_transformProfile=hermes-stable&minify=false&modulesOnly=true&runModule=false&shallow=true
//# sourceURL=http://192.168.1.14:8081/node_modules/%40atcute/lexicons/dist/validations/utils.bundle//&platform=android&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=1&transform.routerRoot=app&transform.reactCompiler=true&unstable_transformProfile=hermes-stable&minify=false&modulesOnly=true&runModule=false&shallow=true
{"version":3,"sources":["---\\dusksky\\node_modules\\@atcute\\lexicons\\dist\\validations\\utils.js"],"sourcesContent":["const segmenter = new Intl.Segmenter();\nexport const getUtf8Length = (str) => {\n    const len = str.length;\n    let u16pos = 0;\n    let u8pos = 0;\n    jump: if (str.charCodeAt(0) < 0x80) {\n        u16pos++;\n        u8pos++;\n        while (u16pos + 3 < len) {\n            const a = str.charCodeAt(u16pos);\n            const b = str.charCodeAt(u16pos + 1);\n            const c = str.charCodeAt(u16pos + 2);\n            const d = str.charCodeAt(u16pos + 3);\n            if ((a | b | c | d) >= 0x80) {\n                break jump;\n            }\n            u16pos += 4;\n            u8pos += 4;\n        }\n        while (u16pos < len) {\n            const x = str.charCodeAt(u16pos);\n            if (x >= 0x80) {\n                break jump;\n            }\n            u16pos++;\n            u8pos++;\n        }\n        return u8pos;\n    }\n    while (u16pos < len) {\n        const code = str.charCodeAt(u16pos);\n        if (code < 0x80) {\n            u16pos += 1;\n            u8pos += 1;\n        }\n        else if (code < 0x800) {\n            u16pos += 1;\n            u8pos += 2;\n        }\n        else if (code < 0xd800 || code > 0xdbff) {\n            u16pos += 1;\n            u8pos += 3;\n        }\n        else {\n            u16pos += 2;\n            u8pos += 4;\n        }\n    }\n    return u8pos;\n};\nexport const getGraphemeLength = (text) => {\n    const iterator = segmenter.segment(text)[Symbol.iterator]();\n    let count = 0;\n    while (!iterator.next().done) {\n        count++;\n    }\n    return count;\n};\n// #__NO_SIDE_EFFECTS__\nexport const lazyProperty = (obj, prop, value) => {\n    Object.defineProperty(obj, prop, { value });\n    return value;\n};\n// #__NO_SIDE_EFFECTS__\nexport const lazy = (getter) => {\n    return {\n        get value() {\n            const value = getter();\n            return lazyProperty(this, 'value', value);\n        },\n    };\n};\nexport const isArray = Array.isArray;\n// #__NO_SIDE_EFFECTS__\nexport const isObject = (input) => {\n    return typeof input === 'object' && input !== null && !isArray(input);\n};\nexport const allowsEval = /*#__PURE__*/ lazy(() => {\n    if (typeof navigator !== 'undefined' && navigator?.userAgent?.includes('Cloudflare')) {\n        return false;\n    }\n    try {\n        const F = Function;\n        new F('');\n        return true;\n    }\n    catch (_) {\n        return false;\n    }\n});\n//# sourceMappingURL=utils.js.map"],"x_facebook_sources":[[{"names":["<global>","getUtf8Length","getGraphemeLength","lazyProperty","lazy","get__value","isObject","lazy$argument_0"],"mappings":"AAA;6BCC;CDgD;iCEC;CFO;4BGE;CHG;oBIE;QCE;SDG;CJE;wBMG;CNE;6COC;CPY"}]],"x_google_ignoreList":[0],"names":["Object","defineProperty","exports","enumerable","get","getUtf8Length","getGraphemeLength","lazyProperty","lazy","isArray","isObject","allowsEval","segmenter","Intl","Segmenter","str","len","length","u16pos","u8pos","jump","charCodeAt","a","b","c","d","x","code","text","iterator","segment","Symbol","count","next","done","obj","prop","value","getter","Array","input","navigator","userAgent","includes","F","Function","_"],"mappings":";;;;;;EACAA,MAAA,CAAAC,cAAA,CAAAC,OAAA;IAAAC,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,aAAA;IAAA;EAAA;EAiDAL,MAAA,CAAAC,cAAA,CAAAC,OAAA;IAAAC,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,iBAAA;IAAA;EAAA;EASAN,MAAA,CAAAC,cAAA,CAAAC,OAAA;IAAAC,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAG,YAAA;IAAA;EAAA;EAKAP,MAAA,CAAAC,cAAA,CAAAC,OAAA;IAAAC,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAI,IAAA;IAAA;EAAA;EAQAR,MAAA,CAAAC,cAAA,CAAAC,OAAA;IAAAC,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAK,OAAA;IAAA;EAAA;EAEAT,MAAA,CAAAC,cAAA,CAAAC,OAAA;IAAAC,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAM,QAAA;IAAA;EAAA;EAGAV,MAAA,CAAAC,cAAA,CAAAC,OAAA;IAAAC,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAO,UAAA;IAAA;EAAA;EA7EA,IAAMC,SAAS,GAAG,IAAIC,IAAI,CAACC,SAAS,CAAC,CAAC;EAC/B,IAAMT,aAAa,GAAIU,GAAG,IAAK;IAClC,IAAMC,GAAG,GAAGD,GA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S,EAAEC,SAAS,EAAEC,QAAQ,CAAC,YAAY,CAAC,EAAE;MAClF,OAAO,KAAK;IAChB;IACA,IAAI;MACA,IAAMC,CAAC,GAAGC,QAAQ;MAClB,IAAID,CAAC,CAAC,EAAE,CAAC;MACT,OAAO,IAAI;IACf,CAAC,CACD,OAAOE,CAAC,EAAE;MACN,OAAO,KAAK;IAChB;EACJ,CAAC,CAAC;AAAC,G"}

it looks like it's Intl.Segmenter

might be able to fix this by adding a fallback for React Native specifically

at least for now i can go and polyfill it myself

also just to add, you'd also probably have to make a polyfill for crypto.subtle.digest in uint8array, for now i just do this

globalThis.crypto = {
  subtle: {
    digest: (algorithm, data) => {
      let digestAlgo;
      switch (algorithm) {
        case "SHA-1":
          digestAlgo = CryptoDigestAlgorithm.SHA1;
          break;
        case "SHA-256":
          digestAlgo = CryptoDigestAlgorithm.SHA256;
          break;
        case "SHA-384":
          digestAlgo = CryptoDigestAlgorithm.SHA384;
          break;
        case "SHA-512":
          digestAlgo = CryptoDigestAlgorithm.SHA512;
          break;
      }

      return digest(digestAlgo, data);
    },
  },
};
sign up or login to add to the discussion
Labels

None yet.

Participants 2
AT URI
at://did:plc:irx36xprktslecsbopbwnh5w/sh.tangled.repo.issue/3mabnvepmza22