Hello! I have used wix velo to build my backend for my website. I finished making backend functionality 2-3 weeks ago and have not touched the code since. I am using git to control version so I know when code was modified. I have done frontend coding only since then. So everything has worked before but now I get error when trying to use imported functions. For example I have a tool that creates a string formatted based on some arguments. This function is imported into multiple other files but now it only returns [Object object]. It is the same for every imported function/module. What could be the issue?
Example code below. The console.log will print [Object object]. However, the exported webMethod can be used correctly from the frontend
import { getStr } from "./test.web";
import { Permissions, webMethod } from "wix-web-module";
function tester(){
const mesg = getStr();
console.log(mesg)
return mesg;
}
export const getAMessage = webMethod(Permissions.Anyone, async () => {
return tester();
});
Do not know what getStr returns, but try console.log(JSON.stringify(mesg)). It looks like you return an object.
Hello!
This is the getStr function:
function getStr(){
return "TEST STRING";
}
export function getStr(){
return "TEST STRING";
}
Don’t see how this returns an object
As @giri-zano said, you are likely receiving a JSON string from the backend web method (getStr
) which needs to be parsed into a Javascript Object.
Please note, web methods are intended to only be defined inside of your backend .web.js
files.
Well this is happening with all my functions and it was working before, as I said. It worked a couple of weeks ago and since I am using git, I can be sure I have a working version. The getStr function is below:
export function getStr(){
return "TEST STRING";
}
Hi there
. If I remember correctly, this is because any imported function from another backend file must have it’s promise resolved, even if the function wasn’t returning a promise in its original file.
So in your example, it would be to update your tester code to call getStr
as if it returns a promise.
**async** function tester(){
const mesg = **await** getStr();
console.log(mesg)
return mesg;
}