
I followed the guide for initiating and deploying a function using the CLI from a folder called "appwrite_functions" where my Appwrite.json resides. My first function called "inviteEmail" resides in "appwrite_functions > functions > inviteEmail" which is a folder that contains the automatically generated files by Appwrite init function (src folder with index.js, and package.json). I deployed the function by running the "appwrite function createDeployment" with correct ID and --entrypoint="src/index.js". The build is successful. I am running Appwrite locally on http://localhost/v1. But when I execute the function manually from Appwrite Console I get the error below. I really cannot understand what the problem is. I have tried editing the entrypoint to --entrypoint="index.js" and to --entrypoint="inviteEmail/src/index.js" in the CLI command. But with the same error on execution. The file "appwrite.json" has these parameters related to the path and entrypoint: "path": "functions/inviteEmail", "entrypoint": "src/index.js",
Error: Cannot find module '/usr/code-start/src/index.js' Require stack:
- /usr/local/src/server.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:940:15) at Module.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:93:18) at /usr/local/src/server.js:55:28 at processTicksAndRejections (node:internal/process/task_queues:96:5)

I tried changing the entrypoint to "--entrypoint="functions/inviteEmail/src/index.js" and then I get this other error message: Error: Cannot find module 'node-appwrite' Require stack:
- /usr/code-start/functions/inviteEmail/src/index.js
- /usr/local/src/server.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:940:15) at Module.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:93:18) at Object.<anonymous> (/usr/code-start/functions/inviteEmail/src/index.js:1:13) at Module._compile (node:internal/modules/cjs/loader:1108:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10) at Module.load (node:internal/modules/cjs/loader:988:32) at Function.Module._load (node:internal/modules/cjs/loader:828:14) at Module.require (node:internal/modules/cjs/loader:1012:19) at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)

[SOLVED] Cannot find module '/usr/code-start/src/index.js'

It seems that there is some issue related to the CLI "createDeployment" function. Ironically this is the one recommended by appwrite when you click on the "Create deployment" button in the Appwrite Console. I tried instead to follow the instruction that is provided inside the automatically generated "ReadMe" file when you run the CLI command "appwrite init function". It says to run "appwrite deploy" from the folder in which the appwrite.json (also automatically created by the "appwrite init function" command) resides. I followed the instruction prompted after running appwrite deplot and it worked out just fine.

did you pass the code
param to specify where your code is?
the createDeployment command does not make use of the appwrite.json and you would have to manually make sure you're specifying the correct code path and entrypoint path

@Steven i did not 🤦♂️ In my defence, it wasn’t apparent that createDeployment ignored appwrite.json nor exactly how the code parameter is specified. Thanks for your reply!
Recommended threads
- error code:524 for functions running lon...
We are having this issue, no longer the function runtime or code, if it goes longer than 1 minute, there's no logs at all, just this error: **error code: 524**
- Invalid `specification` param: Specifica...
I'm self-hosting my appwrite instance on my Macbook, and I created a Python function using the command `appwrite init functions` and it outputed the below into ...
- Local function throws EACCES error when ...
I am developing an Appwrite function locally. Up until now, the process has been as smooth as butter: I edit my files, save them, and this triggers a rebuild of...
