Function execution error : Cannot find module '/usr/local/server/src/function/main.js'
- 1
- Functions
I just deployed appwrite function to my selfhost appwrite connected github also build the function succesfully but I get this error when I try to execute the function for get request inside the appwrite dashboard
`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 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 execute (/usr/local/server/src/server.js:123:28) at /usr/local/server/src/server.js:158:33 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)`
I created the function locally with appwrite cli and didn't change anyting from the generated code just push it to my repo
This is the function code inside main.js
`import { Client } from 'node-appwrite';
// This is your Appwrite function
// It's executed each time we get a request
export default async ({ req, res, log, error }) => {
// Why not try the Appwrite SDK?
//
// const client = new Client()
// .setEndpoint('https://cloud.appwrite.io/v1')
// .setProject(({}).APPWRITE_FUNCTION_PROJECT_ID)
// .setKey(({}).APPWRITE_API_KEY);
// You can log messages to the console
log('Hello, Logs!');
// If something goes wrong, log an error
error('Hello, Errors!');
// The `req` object contains the request data
if (req.method === 'GET') {
// Send a response with the res object helpers
// `res.send()` dispatches a string back to the client
return res.send('Hello, World!');
}
// `res.json()` is a handy helper for sending JSON
return res.json({
motto: 'Build Fast. Scale Big. All in One Place.',
learn: 'https://appwrite.io/docs',
connect: 'https://appwrite.io/discord',
getInspired: 'https://builtwith.appwrite.io',
});
};
What's your repo and build settings for the function?
Fyi, it's best to use 3 backticks for multi line code
Recommended threads
- Function domain not available
Hello, even tho in docs you clearly describe that every function has its domain, I can not see it anywhere in any of my projects. How do I reveal the url of th...
- Inquiry: How to Reduce Cold Start Durati...
Hey! I was using Python for the function runtime, but after reading that Go has the fastest runtime, I switched my code over to Go. However, I'm still seeing co...
- After a GET request is passed to functio...
Create execution in the console can normally retrieve the get parameters。WHy?