Same code, same input but different output in Appwrite function

68 Views Asked by At

I have been on this issue for a while now, and still cannot find a solution.

I'm currently working on a JS/TS Vue App (using the project scaffolding by Quasar framework). We have an on premise Appwrite server with cloud functions enabled.

I'm trying to port some of the code to a single Appwrite function. The function listens for POST requests with a JSON object as the body and returns the result as a JSON object.

Appwrite server version : 1.4.4 (I'm not the admin)

Local node version 20 or 21

Appwrite Node version 18.0

The problem

The issue is : The code in the function doesn't give me the same output as when the code is tested locally.

Context

Basically, I have a 3 Typescript files containing classes A, B and C that import different things from eachother, that's why I include them all for the function. Class A has a method processJson(json): json that is the one I'm trying to turn into a single Appwrite function.

Since Appwrite functions have a Node 18.0 runtime, I first need to transpile the files to Javascript. As I don't have a lot of experience with that, I use the tsup package to build the files like so :

  1. Create an empty dir somewhere
  2. Copy file A.ts, B.ts and C.ts to this dir
  3. CD to the dir
  4. Run npx tsup --format esm A.ts B.ts C.ts which outputs to ./dist/A.mjs ./dist/B.mjs ./dist/C.mjs
  5. Move the dist dir inside the dir of the Appwrite function, so I end up with something like this : somepath/appwrite/functions/myfunction/dist/... and somepath/appwrite/functions/myfunction/main.js (the Appwrite function). Inside main.js I then import the compiled depedency like import { MyClass } from './dist/A.mjs'
  6. Finally, I deploy the function to Appwrite using the CLI. So npx appwrite deploy function, select my function and deploy it.

The function deploys successfully (no build or deploy error) and I'm able to query it through Postman, Python and Appwrite's UI by sending a POST request with the (non stringified) JSON test object that I have. The function does return wihtout crashing, but the result is not the one I expect.

When testing the code locally (with the Quasar app in dev mode), with the same JSON as input I get output A, when testing that same JSON with the function, I get output B.

So far I tried :

  • Deploying the same code on a different function: same issue
  • Using NVM to test locally with the same Node version as Appwrite (Node 18.0) : local test works, same issue for the function. I was thinking maybe some syntax I used was too recent for version 18.0...
  • Make small tweaks to the functions main.js file and redeploy to see if changes were actually pushed : changes are pushed

I don't really know what to do next, as I said, I'm not familiar with Typescript building, and I used the flag --format esm with tsup as I was getting import errors otherwise (CommonJS, etc).

I just have a feeling that the problem has to be related to this somehow, as I feel I've tried everything else so maybe there's something obvious that I'm missing...

0

There are 0 best solutions below