serverless/serverless · error · Error

Handler file was not found: ${handlerFileAbsolutePath}

Error message

Handler file was not found: ${handlerFileAbsolutePath}

What it means

Error "Handler file was not found: ${handlerFileAbsolutePath}" thrown in serverless/serverless.

Source

Thrown at packages/serverless/lib/plugins/aws/dev/local-lambda/runtime-wrappers/node.js:107

  const filePath = path.join(os.tmpdir(), `sls_${process.pid}.json`)

  const stringifiedResult = JSON.stringify(result, null, 2)

  fs.writeFileSync(filePath, stringifiedResult)
}

/**
 * Imports the user handler function from the specified file path.
 * This supports both CommonJS and ESM handler files.
 *
 * @param {string} handlerFileAbsolutePath - Path to handler file
 * @param {string} handlerName - The Handler Name defined in the config file
 * @returns {Promise<Function>}
 */
const importFunction = async (handlerFileAbsolutePath, handlerName) => {
  // Check if the file exists
  if (!fs.existsSync(handlerFileAbsolutePath)) {
    throw new Error(`Handler file was not found: ${handlerFileAbsolutePath}`)
  }

  // Convert the file path to a file URL to ensure
  // it works across different operating systems
  // and for both CommonJS and ESM handler files
  const fileUrl = pathToFileURL(handlerFileAbsolutePath).href

  // Import the handler file. This works for both CommonJS and ESM handler files
  const handlerFunction = (await import(fileUrl))[handlerName]

  // Make sure the handler is a function
  if (typeof handlerFunction !== 'function') {
    throw new Error(`Handler is not a function`)
  }

  // return the function to be invoked
  return handlerFunction
}

View on GitHub (pinned to b9d7ea51c8)

Solutions

  1. Verify the handler file path in the function configuration and that the file exists at that location.

When it happens

Trigger: Thrown at packages/serverless/lib/plugins/aws/dev/local-lambda/runtime-wrappers/node.js:107 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of serverless/serverless@b9d7ea51c8 (2026-08-13). Data as JSON: /api/errors/0df64992b5ff8c95. Report an issue: GitHub.