(0 , _afsBackendWeb.myFunction) is not a function

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 {}} )

Hi, @user1318 !!

I’ve never called a user-defined function from an Automation before, but if we assume that the Automation is failing to call a backend function defined in a .web.js file, have you already tried moving the user-defined function to a regular backend .js file and calling it from there to see if it works? :upside_down_face:

Thanks for the suggestion - it often pays to think outside the box. I tried that but it made no difference. I also tried renaming the function. Still no joy. However, calling a completely different, more complicated function in the same backend file did work…

//
export const getCurrentBookingCode = webMethod(Permissions.Anyone, async (filters) => {
const status = await getUserStatus(filters);
if (status == “ACTIVE”) {
const code = await getBookingCode();
return code;
} else {
return status;
}
})

Surely Velo should not be so fickle as to whether it decides to recognise a function or not?

Have you tried something like this? :upside_down_face:

// backend/AFS-backend.js
export async function userSignup() {
  console.log("userSignup");
  return { success: true };
}

Thanks! Tried it. Still creates the same error message.