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

Async functions are not supported in library? #611

Closed
1 of 2 tasks
itsramiel opened this issue Aug 10, 2024 · 4 comments
Closed
1 of 2 tasks

Async functions are not supported in library? #611

itsramiel opened this issue Aug 10, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@itsramiel
Copy link

Description

I am trying to build a library and I am using async function like this for example:

export function multiply(a: number, b: number): number {
  (async () => {})();

  return a * b;
}

but when I try to use async functions, I get the following error:

[Error: Exception in HostFunction: Compiling JS failed: 9:6:async functions are unsupported Buffer size 840 starts with: 5f5f642866756e6374696f6e2028676c]

Packages

  • create-react-native-library
  • react-native-builder-bob

Selected options

js library

Link to repro

https://github.com/itsramiel/awesome-library

Environment

info Fetching system and libraries information...
System:
  OS: macOS 14.3.1
  CPU: (14) arm64 Apple M3 Max
  Memory: 112.98 MB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.11.1
    path: ~/.nvm/versions/node/v20.11.1/bin/node
  Yarn:
    version: 3.6.1
    path: ~/.nvm/versions/node/v20.11.1/bin/yarn
  npm:
    version: 10.2.4
    path: ~/.nvm/versions/node/v20.11.1/bin/npm
  Watchman:
    version: 2024.06.10.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/itsramiel/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11330709
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 3.3.0
    path: /Users/itsramiel/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.5
    wanted: 0.74.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
@itsramiel itsramiel added the bug Something isn't working label Aug 10, 2024
@satya164
Copy link
Member

Maybe something changed in Expo SDK 51

For now, change example/babel.config.js to the following and it should work:

const path = require('path');
const pak = require('../package.json');
module.exports = function (api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      [
        'module-resolver',
        {
          extensions: ['.tsx', '.ts', '.js', '.json'],
          alias: {
            // For development, we want to alias the library to the source
            [pak.name]: path.join(__dirname, '..', pak.source),
          },
        },
      ],
    ],
  };
};

@TarasOP
Copy link

TarasOP commented Aug 10, 2024

I have the same issue, any async function exported from lib causing the error. (Not using expo)
TypeError: 0, _$$_REQUIRE(_dependencyMap[5](...)let/src/index.tsx").testFunction is not a function (it is undefined)

@itsramiel
Copy link
Author

Maybe something changed in Expo SDK 51

@satya164 but async functions work inside the app. Only asyc functions inside the module doesnt work so i am not sure that is on expo's side or is it?

@satya164
Copy link
Member

@itsramiel By default the code is compiled with babel. in the template we use a different preset for the library code (to prepare for no-compilation step for published libs in the future) which is not compiling the async functions - so then it depends on the engine features.

Looks like async functions aren't fully supported yet. So we'd need to tweak our babel config in the template. Note that it doesn't affect your published library, only the example app usage.

The above babel preset should work for you while we update our config.

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

No branches or pull requests

3 participants