Back

how to upgrade function to V3

  • 0
  • Functions
  • Web
elemin67
12 Sep, 2023, 21:26

I want to upgrade my old functions to V3. I follwed the tutorial on: https://appwrite.io/docs/functions-develop#upgrade

But on front its still showing that I need to update the function to V3. Is there any other tutorials?

TL;DR
The user wants to upgrade their function to V3 but is unsure about some changes. In V3, `req.payload` is no longer supported and should be replaced with `req.body`. The user also needs to add `"commands": "npm install"` in the appwrite.json file for the build command. They are experiencing an issue with package installation and may need to migrate to ES6. The user asks if it only works with ES6 or also with CommonJS, and the response is unclear. They want to upgrade their old functions to V3 but the tutorial they followed is not working. They ask for other tutorials. Solution:
Drake
12 Sep, 2023, 21:26

You'll need to recreate the function

elemin67
12 Sep, 2023, 21:27

do you mean rebuild?

Drake
12 Sep, 2023, 21:28

No, either create a new function or delete your existing function and recreate it with the same ID

elemin67
12 Sep, 2023, 21:29

is it working only with es6 or also with commonjs?

Drake
12 Sep, 2023, 21:30

Probably es6 but I'm not sure

elemin67
12 Sep, 2023, 21:30

oh, then I need to migrate to es6

elemin67
12 Sep, 2023, 21:50

after recreate Cannot find package 'node-appwrite'

elemin67
12 Sep, 2023, 21:51

that is my packege.json

TypeScript
{
  "name": "appwrite-function",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "circular-json": "^0.5.9",
    "crypto-js": "^4.1.1",
    "graphql": "^16.8.0",
    "graphql-request": "^6.1.0",
    "https": "^1.0.0",
    "JSONStream": "^1.3.5",
    "node-appwrite": "^11.0.0",
    "node-fetch": "^2.6.11"
  },
  "devDependencies": {
    "eslint": "^8.49.0"
  }
}
Drake
12 Sep, 2023, 21:52

A function has build commands. You'll need to add npm install for the build command

elemin67
12 Sep, 2023, 21:53

ahh okay, that is new I guess. I cann add it in appwrite.json

TypeScript
"commands": "npm install",
Drake
12 Sep, 2023, 21:57

the idea behind this was to allow anything else you may need as well such as whatever setup needed to install a pivate package or install some chromium driver, etc.

elemin67
12 Sep, 2023, 22:13

"The req object has been updated to use terminology consistent with typical HTTP concepts. You'll now find familiar concepts like headers, body, HTTP methods, and others."

That means req.payload is not any more supported in V3, right? In the new concept it should be req.body?

Drake
13 Sep, 2023, 00:23

yes, req.bodyRaw or req.body. see https://appwrite.io/docs/functions-develop#request

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