Question:
Why does a Wix Automation insist that a user-defined function “is not a function”?
Product:
Wix Studio Editor
What are you trying to achieve:
Trying to get a Wix Automation to run a user-defined backend function.
Error log reports that: “(0 , _afsBackendWeb.userSignup) is not a function”
What have you already tried:
Just about everything. I’m getting old trying to resolve this and it’s taking up too much of my time so any help is appreciated! I know this topic has been raised many times before, and I have followed all the suggested solutions but got nowhere.
Additional information:
It would appear that the Automation does not always link to the latest version of the backend file, but if that is part of the problem how do I fix it and make sure it doesn’t re-occur?
Automation is called by a Velo Trigger, which in turn is called by a button whose onClick event passes the payload data:
//
export const runTrigger = webMethod(
Permissions.Anyone,
async (payload) => {
console.log("Run-Automation/runTrigger line 8")
const triggerMethod = auth.elevate(customTrigger.runTrigger);
await triggerMethod({
triggerId: '61e13e00-9559-4c6c-84c6-69078ce078c5',
payload,
});
console.log("Run-Automation/runTrigger line 17")
}
);
Code behind the Automation, in testTrigger.js, is this:
/**
* Autocomplete function declaration, do not delete
* @param {import('./__schema__.js').Payload} options
*/
import {userSignup} from 'backend/AFS-backend.web';
export const invoke = async () => {
console.log("testTrigger.js/invoke: line 8")
let result = false
result = await userSignup()
if (result) {console.log("testTrigger.js/invoke: email sent", result)
} else {console.log("testTrigger.js/invoke; email not sent", result)
}
return {}
};
Code in backend/AFS-backend.web.js is:
//simplified version for testing. Real code will send an email using sendGrid.
import { Permissions, webMethod } from "@wix/web-methods";
export const userSignup = webMethod(Permissions.Anyone, async () => {console.log("AFS-backend.web.js/userSignup line 132"); return {}} )