Require function not working in production


I use netlify functions for API calls to MongoDB, S3 and more. Locally everything is working fine. When I try this in production it does not work and I can’t seem to know why it doesn’t…

In my functions folder I have a file called test.js.

const test = require("./test/testFunction")
exports.handler = async function (event, context) {
   return test(event,context);

Inside this test.js I require another file named testFunction which returns a statuscode and body.

module.exports = async function (event, context) {
        statusCode: 200,
        body: "sadas"

This works perfectly locally, however in production I got the following error:
Runtime.HandlerNotFound - test.handler is undefined or not exported

I am struggling with this for days and really hope someone can help me solve this.
Site is :

Could you try module.exports = async function handler()?

Unfortunately not working either.
Tried, but still the same error…

Perhaps it is because of the way the functions are bundled in production? Anyway I have no idea how to solve this problem…

Hi @theooog

On common thing that may lead to runtime errors on function is a mismatch between the node version of the build and the function runtime. Can you make sure both are the same and set them using environment variables:

Particularly these:


Try setting them as the same node version you’re running locally.

Hope this helps!

Hi Gualter,

I have set the env variables the same as my local environment.
Unfortunately, I am still seeing the same error :frowning:

:wave: @theooog

It looks like you’ve opened a separate thread that looks quite similar.

In that thread you’ve mentioned the issue might have something to do with including files in subdirectories. As Hrishikesh mentioned, we’ll need a minimal repro to help debug further. Let us know if that’s possible! :slight_smile:

Yes will do that asap and get back! Thanks

1 Like