Skip to content
Back

Function execution error : Cannot find module '/usr/local/server/src/function/main.js'

  • 1
  • Functions
armanhadi
6 Nov, 2023, 08:35

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)`
TL;DR
The user is experiencing an error when trying to execute an Appwrite function. The error message states that the module '/usr/local/server/src/function/main.js' cannot be found. The user created the function locally and pushed it to their repository without making any changes to the generated code. The function was successfully built, but the error occurs when trying to execute a GET request in the Appwrite dashboard. Solution: The error suggests that the main.js module cannot be found. Make sure the file path is correct and that the module is in the specified location. Double-check the repository and build settings to ensure everything is set up correctly. If the file
armanhadi
6 Nov, 2023, 08:36

I created the function locally with appwrite cli and didn't change anyting from the generated code just push it to my repo

armanhadi
6 Nov, 2023, 08:37
TypeScript
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',
  });
};
Drake
8 Nov, 2023, 00:22

What's your repo and build settings for the function?

Fyi, it's best to use 3 backticks for multi line code

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