
I deployed new appwrite function in the appwrite cloud, and on execution this is what I get.
Could not load code file.
Error: Cannot find module 'node-appwrite'
Require stack:
- /usr/local/server/src/function/src/index.js
- /usr/local/server/src/server.js
at Module._resolveFilename (node:internal/modules/cjs/loader:939:15)
at Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:81:25)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/usr/local/server/src/function/src/index.js:3:25)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Module._load (node:internal/modules/cjs/loader:827:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)

@Matej Is this a newly deployed function?

Or do you have deployed an update to the corresponding existing function?

Newly deployed

from CLI

Are you using new function formatting?

What's new formating?

I am using what CLI gave me

Update cli to latest version

And create a new function with CLI so you will get the new format template

👀

What's the latest cli version and how do I update'

nvm I updated

Was about to send 😅

But, I kind of use new formating in my firstly deployed function anyway 🤔

I'll try to deploy new one and see if it changes anything

ReferenceError: exports is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and '/usr/local/server/src/function/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. at file:///usr/local/server/src/function/src/main.js:2:23 at ModuleJob.run (node:internal/modules/esm/module_job:198:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:409:24) at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15) at async execute (/usr/local/server/src/server.js:126:32) at async /usr/local/server/src/server.js:158:13

Ok this is now probably typescript issue

this is my tsconfig
{ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "outDir": "./src", "rootDir": "./dev", "strict": true, "moduleResolution": "node", "esModuleInterop": true }, "include": [ "dev/**/*", ], "exclude": ["node_modules"] }

SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>) at Module.default (file:///usr/local/server/src/function/src/main.js:20:26) at execute (/usr/local/server/src/server.js:141:48) at async /usr/local/server/src/server.js:158:13
Making progress. 😄

@D5 Ok and I was also doing req.payload
instead req.body
Along with few hickups here and there, thing are now working.
Also updated tsconfig.json module to ES2022
Can close this, ty 🙂

Perfect. Sorry for not replying faster

[SOLVED] Appwrite function can't find node-appwrite module
Recommended threads
- Failed to verify JWT. Invalid token: Exp...
Hi I am trying to call a function from my mobile app, but I am receiving "Invalid token expired." My code looks more or less like this ```ts // from my app ...
- How do I pair Polar.sh + Hono + Appwrite...
This is what all it required by polar to see the webhook data. Managing with webhook data is not an issue, but how do I pair this all with appwrite functions st...
- The function became slower after being e...
I used the Python SDK and set `xasync=True` in `create_execution`, expecting it to execute quickly on another worker. However, the execution ended up taking sev...
