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
context
object
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
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Send Email Verification With REST
I am using REST to create a user on the server side after receiving form data from the client. After the account is successfully created i wanted to send the v...
- Use different email hosts for different ...
Hello, I have 2 projects and i want to be able to set up email templates in the projects. Both projects will have different email host configurations. I see ...