1

I'm using back4app as backend service to deploy my app, developed in React Native ans JS. I'm testing how to use the 'Cloud Code Functions' of back4app right now...

As I'm a beginner in back4app, I found a problem while using their guide. I'm facing this message error: 'async functions' is only available in ES8 (use 'esversion: 8').:

Back4app Side:

import Parse from 'parse/react-native.js';
import AsyncStorage from '@react-native-async-storage/async-storage';


//Initializing the SDK
Parse.setAsyncStorage(AsyncStorage);
//Paste below the Back4App Application ID AND the JavaScript KEY
Parse.initialize('YOUR_APPLICATION_ID_HERE', 'YOUR_JAVASCRIPT_KEY_HERE');
//Point to Back4App Parse API address 
Parse.serverURL = 'https://parseapi.back4app.com/';

//This is a hello function and will log a message on the console
Parse.Cloud.define("hello", async (request) => {
    console.log("Hello from Cloud Code!");
    return "Hello from Cloud Code!";
});

my app:

const helloFunction = await Parse.Cloud.run("hello");

I know the problem comes from the asynchronous function, but I can't find any solution. What am I doing wrong?

Jacob van Lingen
  • 8,989
  • 7
  • 48
  • 78

2 Answers2

0

When using the cloud code, you do not need to do any kind of initialization as it is already done on the Back4app servers.

So in your main.js file please remove:

  1. The import statements. Lines 2 and 3.

  2. The Parse initialization. The lines 6,8, and 10.

Jacob van Lingen
  • 8,989
  • 7
  • 48
  • 78
Tanzim Chowdhury
  • 3,020
  • 2
  • 9
  • 21
  • Thank you for answering, I have considered your points and I did update my post.. after that, what's the problem in the code? – Omar KASSARA Dec 02 '21 at 14:15
  • After that, the code should work. Are you still getting errors? – Tanzim Chowdhury Dec 03 '21 at 05:48
  • it doesn't work, I have this error message: "'async functions' is only available in ES8 (use esversion:8)" on back4app side – Omar KASSARA Dec 03 '21 at 10:11
  • Can you please try calling that cloud function through REST API? https://docs.parseplatform.org/rest/guide/#calling-cloud-functions – Tanzim Chowdhury Dec 03 '21 at 10:55
  • The URL for the call would be https://parseapi.back4app.com/functions/hello – Tanzim Chowdhury Dec 03 '21 at 10:57
  • to give more precisions, the error come from the word 'await' here: const helloFunction = await Parse.Cloud.run("hello"); I get this message: Syntax Error Unexpected reserved word 'await'. when I remove 'await', the error disappear and I don't get any result – Omar KASSARA Dec 05 '21 at 13:43
  • Yes, that might be an issue with the SDK. But have you tried calling your cloud code from REST? if it works that means your cloud code is fine. – Tanzim Chowdhury Dec 06 '21 at 10:23
  • Yes, I contacted back4app help service this morning, and they confirm the issue with the SDK... even more as you mentionned, they suggest to use code form REST... Thank you so much for your help Tanzim Chowdhury – Omar KASSARA Dec 06 '21 at 13:05
0

To really answer the question, the error message is a false positive! Probably the online editor is not configured right, so it shows these warnings accidentally...

Just as the guide tells you, you can use the async keyword if you got a running 3.x Parse Server. It should be safe to use this, as per default Parse Server 4.x is used (the server can be changed via App Settings > Server Settings > Manage Parse Server).

Jacob van Lingen
  • 8,989
  • 7
  • 48
  • 78