Effect CommunityEC
Effect Community5w ago
3 replies
Zoxive

Issue with Effect-smol and React Native: Babel Transforms and Hermes Compatibility

I'm playing with effect-smol and react native. Small gotcha I just hit when i started using Schemas. You get some crazy error like: "ERROR TypeError: Function is not a constructor, js engine: hermes"
Little deep diving later.. Theres some babel transforms that transpile the JS to be compatible with the hermes js engine. And it replaces rest parameters with stuff like for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; }
but the Schema.ts file declares Array. so boom.

TL;DR if anyone else is playing with effect-smol and react native use a patch to make sure it uses the transpiled code uses global.Array so you can use Effect Schemas

@babel%2Fplugin-transform-parameters@7.27.7.patch
diff --git a/lib/rest.js b/lib/rest.js
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000001 100644
--- a/lib/rest.js
+++ b/lib/rest.js
@@ -8,7 +8,7 @@ var _core = require("@babel/core");
var _shadowUtils = require("./shadow-utils.js");
const buildRest = _core.template.statement(`
for (var LEN = ARGUMENTS.length,
- ARRAY = new Array(ARRAY_LEN),
+ ARRAY = new (globalThis.Array)(ARRAY_LEN),
KEY = START;
KEY < LEN;
KEY++) {
Was this page helpful?