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
- No server error on selfhosted appwrite
Please help me, my clients is ask what happen on their data? How can i make it up again?
- Worker functions stuck on "Fetched 0 fun...
Appwrite Version: 1.9.0 Bug Description: The appwrite-worker-functions container gets stuck in an infinite loop logging "Fetched 0 functions..." while scheduled...
- Upgrading selfhost version?
It is okay to upgrade version to higher one, of my current version is 1.7.4 to 1.8.1. Is that safe to do cause my clients already have data on that? Also is a...