Skip to content

Unable to use ArkType with Expo #1027

Closed

Description

@eduardo-gualberto

Report a bug

🔎 Search Terms

@babel/plugin-transform-class-static-block
expo

🧩 Context

  • ArkType version: 2.0.0-dev.25
  • TypeScript version (5.1+): 5.5.2
  • Other context you think may be relevant (JS flavor, OS, etc.): MacOS, Apple Silicon, React Native, Expo

🧑‍💻 Repro

I'll leave a repository containing a minimal reproduction code: https://github.com/eduardo-gualberto/arktype-repro-01

import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
import { type } from "arktype";

export default function App() {
  const myType = type({
    test: "string",
    test2: "number>5",
  });
  return (
    <View style={styles.container}>
      <Text>Open up App.tsx to start working on your app!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});

I noticed I could not make arktype work with a create-expo-app (typescript templated) project.

It first complains about a missing babel plugin called plugin-transform-class-static-block. Such as bellow.

Screenshot 2024-06-24 at 16 23 07

Then, after installing the plugin and adding it to babel.config, the error changes to

Screenshot 2024-06-24 at 16 26 41

Activity

  1. added
    bug
    on Jun 24, 2024
  2. ssalbdivad commented on Jun 24, 2024

    @ssalbdivad
    Member

    Thanks for logging this! It looks like a bug with the way Expo/babel are parsing the TypeScript output for decorators.

    I have my tsconfig target set to ES2022, so as long as the parser supports at least that, it should work out of the box.

    I'm not sure about intersection.equals being undefined in hermes, but given that it works in every other runtime I've tested, it also seems worth opening an issue with the maintainers of that project to see if they have an idea what's going on.

    I'm happy to try and accommodate this environment if there are specific, targeted changes I can make to do so.

  3. eduardo-gualberto commented on Jun 24, 2024

    @eduardo-gualberto
    Author

    Thank you for replying so quickly!

    It seems there are quite a few problems just like that with the hermes interpreter, not my lucky day.

    The crazy thing is that using version 2.0.0-dev.0 of ArkType the problem seems to go away.

  4. ssalbdivad commented on Jun 24, 2024

    @ssalbdivad
    Member

    I can't say for sure what was in the newer releases that wasn't in that one, but I can say I can't maintain a limited feature set based on what Hermes supports going forward.

    If there's a specific problem I can easily address please do let me know as I'd love to help. I'll close this issue for now.

  5. moved this from To do to Done (merged or closed) in arktypeioon Jun 24, 2024
  6. dolgim commented on Feb 13, 2025

    @dolgim

    Hello!

    I encountered the same issue as described above. After investigating the cause, I found that in the Hermes environment, the prototype of the instance returned by the invert method of the Disjoint class is the prototype of Array, not Disjoint. In other words, the intersection instanceof Disjoint code in the union.ts file evaluates to false. (I believe the withPrefixKey method might have the same issue.)

    This seems to be related to Hermes' limitations, specifically the "use of constructor property when creating new Arrays in Array.prototype methods" or lack of support for Symbol.species as mentioned in the Hermes documentation (https://github.com/facebook/hermes/blob/main/doc/Features.md).

    I managed to get it working in my environment by modifying the code as follows:

     invert(): Disjoint { 
    - 	return this.map(entry => ({ 
    +  	return new Disjoint(...this.map(entry => ({ 
     		...entry, 
     		l: entry.r, 
     		r: entry.l 
    - 	})) as Disjoint 
    + 	})))
     } 

    While the ArkType code itself seems correct according to ECMAScript specifications (which expect a Disjoint instance to be returned), I was wondering if you might consider making some adjustments for better runtime compatibility across different environments.

    Thank you for creating such an excellent library. It has been providing me with a great development experience!

  7. bsluther commented on Mar 4, 2025

    @bsluther

    I managed to get it working in my environment by modifying the code as follows:

    This worked for me too, thanks a bunch @mark-lendit. I had spent a while trying to get things working in React Native without any luck.

    In case it helps anyone else, these are the steps that got arktype working in my Expo project. I'm not positive if they are all required, but I tried a number of combinations without luck:

    • Install babel-plugin-transform-import-meta and use it in babel.config.js. I used this setting specifically:
    module.exports = function (api) {
      api.cache(true)
      return {
        presets: ['babel-preset-expo'],
        plugins: [
          ["babel-plugin-transform-import-meta", { "module": "ES6" }]
        ]
      }
    }
    • Make the change to @ark/schema/out/shared/disjoint.js as described by @mark-lendit .
    • Add config.resolver.unstable_enablePackageExports = true to metro.config.js.
    • Used node version 22. I'm not sure what was going on here, but that was the last step that got things working. Weirdly, I can now run things with node 18.
    • I'm using yarn, also not sure if it matters, but had some different problems with pnpm before.
    • If you are getting things setup, don't forget to clear your build cache, eg npx expo start --clear.

    Happy that I can use Arktype now, it seems excellent.

  8. ssalbdivad commented on Mar 4, 2025

    @ssalbdivad
    Member

    @mark-lendit Thanks so much for root causing this! I'm going to reopen this issue to track making the suggested adjustment to the package and hopefully adding some CI tests for Hermes.

  9. moved this from Done (merged or closed) to To do in arktypeioon Mar 4, 2025
  10. moved this from To do to Planned in arktypeioon Mar 4, 2025
  11. ssalbdivad commented on Mar 5, 2025

    @ssalbdivad
    Member

    Just updated this in 2.1.4 (fixed)! Hopefully that addresses the immediate problem.

    I'd like to get a more permanent solution in place for testing if anyone here has an idea of the most straightforward way to execute vanilla-JS logic like ArkType's test suite with hermes, would love to get some help:

    #1340

  12. moved this from Planned to Done (merged or closed) in arktypeioon Mar 5, 2025
  13. dolgim commented on Mar 5, 2025

    @dolgim

    Just updated this in 2.0.4! Hopefully that addresses the immediate problem.

    I'd like to get a more permanent solution in place for testing if anyone here has an idea of the most straightforward way to execute vanilla-JS logic like ArkType's test suite with hermes, would love to get some help:

    #1340

    @ssalbdivad Thank you for your quick work! You mentioned that the issue was fixed in version 2.0.4, but I believe it’s 2.1.4. I have confirmed that the problem has been resolved in 2.1.4. Thank you once again.

  14. ssalbdivad commented on Mar 5, 2025

    @ssalbdivad
    Member

    @mark-lendit Whoops, yes thanks for the correction!

  15. salemkode commented on Mar 24, 2025

    @salemkode

    I have another issues in expo ~52.0.39

    module.exports = (api) => {
      api.cache(false);
    
      return {
        presets: [
          ["babel-preset-expo", { jsxImportSource: "nativewind" }],
          "nativewind/babel",
        ],
        plugins: [
          "react-native-reanimated/plugin",
          ["babel-plugin-transform-import-meta", { module: "ES6" }],
        ],
      };
    };

    Image

    Unable to resolve "@ark/schema/config" from "node_modules/.pnpm/[email protected]/node_modules/arktype/out/config.js"
    
  16. ssalbdivad commented on Mar 24, 2025

    @ssalbdivad
    Member

    @salemkode It looks like it's not resolving package.json's exports field. exports has been supported since Node 12 and apparently has been in React Native for a couple years, though I'm not sure what if anything needs to be done to enable it at this point:

    https://reactnative.dev/blog/2023/06/21/package-exports-support

  17. shovel-kun commented on Apr 11, 2025

    @shovel-kun

    If you get @ark/schema/config could not be found error in your Expo/React Native project, you need to add unstable_enablePackageExports: true to your metro config.

    Example:

    const { getDefaultConfig } = require("expo/metro-config");
    const { mergeConfig } = require("@react-native/metro-config");
    
    /** @type {import('expo/metro-config').MetroConfig} */
    const defaultConfig = getDefaultConfig(__dirname);
    
    const config = {
      resolver: {
        unstable_enablePackageExports: true,
      },
    };
    
    module.exports = mergeConfig(defaultConfig, config);
  18. added a commit that references this issue on Jan 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

  • Status
    Done (merged or closed)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions