Back

1.4.3 NodeJS Function context & documentation discrepancy

  • 0
  • Functions
RedLeeder
18 Sep, 2023, 15:40

So I am trying to take full advantage of the new function capabilities via context.log & context.error but am running into issues with getting that to work.

Current Implementation

index.js

TypeScript
// I've tried both
module.exports = async function (req, res, log, error) {
// module.exports = async function ({ req, res, log, error }) {
...
log("blah blah blah")
...
}

I recieve this error

TypeError: log is not a function

package.json in case that matters

TypeScript
{
    "name": "appwrite-function",
    "version": "1.0.0",
    "description": "",
    "main": "src/index.js",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
        "node-appwrite": "^11.0.0",
    }
}

I would also like to point out that the documentation for NodeJS Functions is different depending on where you look:

https://appwrite.io/docs/functions-develop vs https://github.com/appwrite/functions-starter/blob/main/node-16.0/src/index.js

I couldn't get the first example to work due to module errors around import so I just used the functions-starters. I am using appwrite-cli if that helps.

Appreciate any insight!

TL;DR
The user was experiencing issues with the 1.4.3 NodeJS function context and a discrepancy in the documentation. They found that creating a new function with the 1.4 syntax resolved the issue. It was also mentioned that old functions needed to be recreated due to being read-only. Additionally, there was a bug in the appwrite-cli which prevented the user from updating to the latest version. The solution was to install the CLI from the Windows Terminal, which pulled the correct version. Finally, the user shared their current implementation and package.json file. Solution: Create a new function using the 1.4 syntax, recreate
Drake
18 Sep, 2023, 16:30

https://github.com/appwrite/functions-starter/blob/main/node-16.0/src/index.js

This is the pre-1.4 syntax

What version of the CLI are you using? (appwrite -v)

RedLeeder
18 Sep, 2023, 16:31

0.17.1

RedLeeder
18 Sep, 2023, 16:31

*The functions may have been originally templated via an older version of the cli/appwrite

Drake
18 Sep, 2023, 16:34

that is really old...meant for Appwrite 0.14.x: https://github.com/appwrite/sdk-for-cli/blob/0.17.1/README.md

Drake
18 Sep, 2023, 16:34

If you're on Appwrite 1.4.3, you should be using 4.1.0 of the CLI: https://github.com/appwrite/sdk-for-cli/blob/4.1.0/README.md

RedLeeder
18 Sep, 2023, 16:36

geez, you're not kidding. I thought npm i -g appwrite-cli would automatically pull the latest version but I guess not

RedLeeder
18 Sep, 2023, 16:40

Okay so when running npm i from WSL it would only ever pull v0.17.1...when I installed it from just a general windows terminal it did indeed pull v4.1.0 and that is reflected in WSL now

RedLeeder
18 Sep, 2023, 16:40

Can't wait till you guys sort out the Windows appwrite-cli bugs <:appwriteheart2:1073243188954935387>

RedLeeder
18 Sep, 2023, 16:41

I'll refactor the function to 1.4 syntax and report back

Drake
18 Sep, 2023, 16:42

uhhh in general, i don't think npm i will upgrade your package

Drake
18 Sep, 2023, 16:43

what bug?

RedLeeder
18 Sep, 2023, 16:44

I uninstalled appwrite-cli and then reinstalled it from both WSL and Default Windows Terminal...only the windows terminal pulled v4.1.0

RedLeeder
18 Sep, 2023, 16:47

I swear to god...if I've been using WSL this whole time because I was using an outdated appwrite-cli...

https://github.com/appwrite/sdk-for-cli/issues/29

RedLeeder
18 Sep, 2023, 16:47

Yup, was fixed in 0.18.4.

RedLeeder
18 Sep, 2023, 16:48

Classic PEBCAK situation

RedLeeder
20 Sep, 2023, 18:48

Works now. I also missed the fact that my old functions were Read Only so I had to remake them entirely instead of simply updating the code

Drake
20 Sep, 2023, 20:15

you do need to recreate the function 🧐

Drake
20 Sep, 2023, 20:16

are you saying you just created a new deployment with the 1.4 syntax and it worked?

RedLeeder
20 Sep, 2023, 21:01

I don't believe I could get new deployments to work on the existing function (which was originally created before 1.4.x via CLI v0.17.1). Definitely could have been a me issue, but even after I updated the package.json and main.js files to the newer formats, it wasn't taking.

I ended up just creating an entirely new function which worked.

Drake
20 Sep, 2023, 22:51

you can create new deployments, on old functions, but they must be in the old format. the new format will only be used on new functions created after upgrading to 1.4

RedLeeder
20 Sep, 2023, 23:13

That'd be why they weren't working! Out with the old, in with the new!

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more