question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RCT_EXPORT_METHOD that takes no parameters and returns a promise throws error

See original GitHub issue

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

yes

Environment

Environment: OS: macOS Sierra 10.12.6 Node: 8.9.0 Yarn: 1.3.2 npm: 5.5.1 Watchman: 4.9.0 Xcode: Xcode 9.1 Build version 9B55 Android Studio: 3.0 AI-171.4408382

Packages: (wanted => installed) react: 16.0.0-beta.5 => 16.0.0-beta.5 react-native: 0.49.3 => 0.49.3

Target Platform: iOS (10.3)

Steps to Reproduce

(Write your steps here:)

  1. Create a native module that returns a promise

TestNativeModule.h

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>

@interface TestNativeModule : NSObject <RCTBridgeModule>
@end

TestNativeModule.m

@implementation TestNativeModule
RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(get: findEventsWithResolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject) {
  resolve("test");
}
@end
  1. Call it from JS:
const promise = NativeModules.CallToAdventureNative.get();
  1. See the error:
CallToAdventureNative.get was called with 0 arguments but expects 1 arguments. If you haven't changed this method yourself, this usually means that your versions of the native code and JavaScript code are out of sync. Updating both should make this error go away.

Note: It works if you pass Anything to the .get function.

Expected Behavior

It would call the function.

Actual Behavior

The error posted above.

Reproducible Demo

It’s a native module, can’t repro the web

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
floriancargoetcommented, Dec 9, 2017

Try:

RCT_EXPORT_METHOD(get:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject) {
  resolve("test");
}
1reaction
cmwallcommented, Apr 24, 2018

I’m just checking in on this. I’m also running into this error. Is there a better solution than that empty string hack?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to bridge React Native Promise to Swift - Stack Overflow
I am currently working on a React native project for which I need to add some logic which has been written in swift....
Read more >
Promise.prototype.then() - JavaScript - MDN Web Docs
The then() method of a Promise object takes up to two arguments: ... Makes .then() return a rejected promise throw new Error("Oh no!...
Read more >
iOS Native Modules
Let's follow the example below and call RCT_EXPORT_MODULE without any arguments. As a result, the module will be exposed to React Native ...
Read more >
Error handling with promises - The Modern JavaScript Tutorial
new Promise((resolve, reject) => { throw new Error("Whoops! ... alert(`The unknown error has occurred: ${error}`); // don't return anything ...
Read more >
Why Promise.all doesn't reject when a non-promise throws an ...
It takes an array of promises as its argument and returns a single ... elements (passed as an argument to Promise.all()) throws an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found