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
- HTTP POST to function returning "No Appw...
Hi everyone, Iβm running into an issue with my self-hosted Appwrite instance. Iβve set up my environment variables (APPWRITE_FUNCTION_PROJECT_ID, APPWRITE_FUNC...
- Can't add dart 3.5 runtime
Modified the `.env` to enable dart 3.5 runtime on my self-hosted instance but still can't find the runtime when creating a new function. I manually pulled the i...
- How to verify an user using AppWrite Fun...
I have seen similar questions but none whose solutions serve me. I have a function to verify a user with their secret and their id: https://blahblah.appwrite.gl...