I'm not sure if I'm doing anything wrong with the syntax. I've copied one of the example codes and removed the logic and left only 2 lines of log to test it. Below is the code
export default async function ({ req, res, log, error }) {
log("Request received");
log("--------");
log("Request Object: ==>>", req);
return res.send("Hello World");
}
any idea why I'm getting this error? any help will be appreciated
To what version of Appwrite you're deploying this function?
the latest version. 1.4.2
- How have you created the function?
- What version is your Appwrite cli?
- Functions tab -> create function -> manually -> uploaded the tar file -> specified entry point (index.js) -> create -> activate
- i did it manually from the console cuz it was only for testing to check what info i get in the
contextobject
It think it may be a node version problem
Is this function from before 1.4?
What is that tar file includes?
It's recommend using the latest version of Appwrite cli > 4.0.0 and deploy a function using this method.
I am also facing the same issue 😦
Update: Changing the entry point filename from "index.js" to "index.mjs" solved the issue 🙂
That might be the case. appwrite currently uses Node v16 which is now end of life, according to this post
nope. i copied this code from the official doc and removed all the logic and kept only 3 logs to test it out
This is the function for the deployment. I meant did you create this function before or after 1.4?
shown in the ss. node_modules doesn't have any modules actually
and about deploying with Appwrite cli, I wonder what difference it makes when we do manual deployment. I've used the manual deployment before (before 1.4) and it worked well
after 1.4
Update: Changing the entry point filename from "index.js" to "index.mjs" solved the issue 🙂 I just tried and it worked for me as well. but i wonder what the issue was in the first place
What's in your package.json ?
{
"name": "trabo-server-functions",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
What if you add type like here: https://github.com/appwrite/templates/blob/8ed54e059cb44c68059fe8bbca0bf76ea077f283/node/starter/package.json#L6
yeah it works now. just like @RAKU suggestion, we needed to convert it to a module. but i wonder what's the problem when we don't keep it as a module?
Maybe it defaults to common js which has a different syntax
[SOLVED] Unexpected token 'export' error in function
Recommended threads
- Does a user need to be registered in App...
If I want to send an email (for example, to xyz@gmail.com) from an Appwrite Cloud Function, does that email address need to be registered as a user in Appwrite?...
- endpoint variable
Appwrite Sites passes e.g. APPWRITE_SITE_API_ENDPOINT to the site, but i need this variable in Next.js in my Client-Side-Page. How can i pass it? Next.js only p...
- Function Go module undefined
Attached image, why module is undefine, also when I'm running `appwrite run function`, it still undefine, why?