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

RCT_EXPORT_METHOD that takes no parameters and returns a promise throws error #17037

Closed
JPTeasdale opened this issue Dec 1, 2017 · 10 comments
Closed
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@JPTeasdale
Copy link

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

@caschomburg123
Copy link

caschomburg123 commented Dec 2, 2017 via email

@floriancargoet
Copy link
Contributor

Try:

RCT_EXPORT_METHOD(get:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject) {
  resolve("test");
}

@stale
Copy link

stale bot commented Feb 7, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 7, 2018
@anderskev
Copy link

anderskev commented Feb 13, 2018

FWIW this is still broken as of 0.53, although I believe you can get around it via the hacky solution stated above:

In the Objective-C

RCT_EXPORT_METHOD(someMethodName: (NSString *)blank
        resolve(RCTProniseResolveBlock)resolve
        reject(RCTPromiseRejectBlock)reject) {
    // Do something
    resolve(nil);
}

Then in JS

SomeModule.someMethodName("");

Like I said, super hacky.

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 13, 2018
@floriancargoet
Copy link
Contributor

@anderskev Have you tried:

RCT_EXPORT_METHOD(someMethodName:(RCTPromiseResolveBlock)resolve
                  reject:(RCTPromiseRejectBlock)reject) {
  // Do something
  resolve(nil);
}

?
This is the expected Objective-C signature for a method receiving only resolve & reject arguments.

@facebook-github-bot
Copy link
Contributor

Something went wrong executing that command, @hramos could you take a look?

@react-native-bot
Copy link
Collaborator

Thanks for posting this! It looks like you may not be using the latest version of React Native, v0.53.0, released on January 2018. Can you make sure this issue can still be reproduced in the latest version?

I am going to close this, but please feel free to open a new issue if you are able to confirm that this is still a problem in v0.53.0 or newer.

How to ContributeWhat to Expect from Maintainers

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon. and removed Failed Commands labels Feb 24, 2018
@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 24, 2018
@PerspectivesLab
Copy link

PerspectivesLab commented Mar 16, 2018

the function

RCT_EXPORT_METHOD(get: findEventsWithResolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject) {
  resolve("test");
}

should be:

RCT_EXPORT_METHOD(get: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  resolve("test");
}

@cmwall
Copy link

cmwall commented 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?

@floriancargoet
Copy link
Contributor

@cmwall The issue here was a incorrect syntax, there's no need for an empty string. What's your native method signature?

@facebook facebook locked as resolved and limited conversation to collaborators Feb 24, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Feb 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

8 participants