Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isomorphic-webcrypto not resolved correctly with react-native expo #93

Open
aurmartin opened this issue Nov 2, 2024 · 1 comment · May be fixed by #94
Open

isomorphic-webcrypto not resolved correctly with react-native expo #93

aurmartin opened this issue Nov 2, 2024 · 1 comment · May be fixed by #94
Assignees
Labels
bug Something isn't working

Comments

@aurmartin
Copy link

Describe the bug
The random module does not work with react-native expo.

I have followed the instructions in the README.md (installed isomorphic-webcrypto and enabled unstable_enablePackageExports).

The isomorphic-webcrypto module isn't resolved correctly.

Error message: TypeError: Cannot read property 'ensureSecure' of undefined, js engine: hermes

Stacktrace:

image

To Reproduce

  1. npx create-expo-app@latest
  2. Import import * as random from 'lib0/random' and use random.rand()
  3. npx expo start
  4. Open on android emulator

Expected behavior
Lib0 random module works with react-native expo.

Environment Information

  • Expo: 51.0.28
  • Lib0: 0.2.98

Additional context
A workaround I have found is to hack the metro resolver:

// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require("expo/metro-config");

/** @type {import('expo/metro-config').MetroConfig} */
const defaultConfig = getDefaultConfig(__dirname);

console.warn("THERE")

const config = defaultConfig;

config.resolver.unstable_enablePackageExports = true;

config.resolver.resolveRequest = (context, moduleName, platform) => {
  if (platform !== "web" && moduleName === "isomorphic-webcrypto") {
    return {
      filePath:
        __dirname + "/node_modules/isomorphic-webcrypto/src/react-native.js",
      type: "sourceFile",
    };
  }

  return context.resolveRequest(context, moduleName, platform);
};

module.exports = config;
@aurmartin aurmartin added the bug Something isn't working label Nov 2, 2024
@aurmartin aurmartin linked a pull request Nov 2, 2024 that will close this issue
@aurmartin
Copy link
Author

I also opened a PR with a fix for this issue: #94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants