Back

how to use template from git for selfhosted 1.4.9 appwrite?

  • 0
  • Self Hosted
  • Functions
vontdeux
4 Dec, 2023, 12:34

any one knows a guide on how to deploy this template here https://github.com/appwrite/templates/tree/main/node/storage-cleaner

to appwrite function manually? i pull the code, tar.gzip the src folder, and used 1.4.9's function to select upload manually and when i execute the function, i got this error

Could not load code file. Error: Cannot find module '/usr/local/server/src/function/index.js' Require stack: /usr/local/server/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 execute (/usr/local/server/src/server.js:123:28) at /usr/local/server/src/server.js:158:33 at processTicksAndRejections (node:internal/process/task_queues:96:5)

TL;DR
The user is having trouble using a template from GitHub for their self-hosted Appwrite 1.4.9 app. They are getting errors related to the file structure and module imports. They are unsure how to properly deploy the template as an Appwrite function. There is no solution provided in the support thread.
Drake
4 Dec, 2023, 12:39

Did you make sure to include npm install as part of the build command?

vontdeux
4 Dec, 2023, 12:47

if i add that for build command, another error comes out

/usr/local/server/src/function/main.js:1 import AppwriteService from './appwrite.js'; ^^^^^^

SyntaxError: Cannot use import statement outside a module at Object.compileFunction (node:vm:355:18) at wrapSafe (node:internal/modules/cjs/loader:1038:15) at Module._compile (node:internal/modules/cjs/loader:1072:27) 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) at require (node:internal/modules/cjs/helpers:93:18) at execute (/usr/local/server/src/server.js:123:28)

thanks for you reply @Steven , i'm quite new to 1.4 , everything's so much awesome that i felt lost

Drake
4 Dec, 2023, 12:48

Please make sure to format multi line stuff like this with backticks like you would in markdown

Drake
4 Dec, 2023, 12:48

Wait is the function created after upgrading to 1.4?

vontdeux
4 Dec, 2023, 12:56

yes, its the function i try to create using template available on github basically there was another script i use for 1.3, but since i upgraded to 1.4, i found that the script no longer compatible for 1.4, i ask around and someone here pointed to use https://github.com/appwrite/templates/tree/main/node/storage-cleaner what i did just pull the template script, and tar.gz it then create a new deployment on my 1.4 appwrite

Drake
4 Dec, 2023, 12:58

Your function from before 1.4 will continue to work with the old syntax.

To use the new one, you'll need to create a new function

vontdeux
4 Dec, 2023, 12:59

yes, got that, im creating a new function to clear storage from another project that did not have function yet

vontdeux
4 Dec, 2023, 12:59

but unable to do it successfully so far

Drake
4 Dec, 2023, 13:00

so what's the error in the new function?

vontdeux
4 Dec, 2023, 13:06

if i create tar.gzip from entire folder of "storage-cleaner", upload it manually(nodejs runtime) as new function, then execute it with "npm install" as build command, i will get this error Could not load code file. Error: Cannot find module '/usr/local/server/src/function/main.js' Require stack:

  • /usr/local/server/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 execute (/usr/local/server/src/server.js:123:28) at /usr/local/server/src/server.js:158:33 at processTicksAndRejections (node:internal/process/task_queues:96:5)
vontdeux
4 Dec, 2023, 13:16

i did not touch anything for the folder structure of "storage-cleaner"

vontdeux
4 Dec, 2023, 13:17

my "create deployment" screen

vontdeux
4 Dec, 2023, 13:18

my execute screen

vontdeux
4 Dec, 2023, 13:19

the error

Drake
4 Dec, 2023, 13:30

are you crating an archive of the contents of the folder or the folder itself?

vontdeux
4 Dec, 2023, 14:21

the folder itself

vontdeux
4 Dec, 2023, 14:23

just tried it with the content of the folder , same error Could not load code file. Error: Cannot find module '/usr/local/server/src/function/main.js' Require stack:

  • /usr/local/server/src/server.js
vontdeux
6 Dec, 2023, 12:04

@Steven any idea?

Drake
6 Dec, 2023, 18:30

Still probably a problem with the folder structure.

How about to initialize a function using the Appwrite CLI and execute that starter function?

vontdeux
6 Dec, 2023, 23:53

i tried it this morning, and its not folder structure, its "entrypoint" , as the file is in "storage-cleaner/src", i need to add "src/main.js" in the entrypoint when uploading it manually

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