Support Forums

Netlify function can't find .hbs file

I’m having a problem with netlify functions.

When trying to read a file (fs.readFile()), it can’t be found by the production version of my function.
Reading this file and others works perfectly fine in development (netlify dev) so I don’t get why it doesn’t work in prod.

Here’s the full error message:

ERROR  Uncaught Exception 	{"errorType":"Error","errorMessage":"ENOENT: no such file or directory, open '/var/task/app/mail/confirm_email/email_switch.hbs'","code":"ENOENT","errno":-2,"syscall":"open","path":"/var/task/app/mail/confirm_email/email_switch.hbs","stack":["Error: ENOENT: no such file or directory, open '/var/task/app/mail/confirm_email/email_switch.hbs'"]}

I’m trying to read the file from mail.js, a js file located within the app folder. The file I’m trying to read is in the ‘/mail’ folder, which itself is located in the app folder. Sounds a bit confusing so I’ll leave an image.

netlify support

Any help would be greatly appreciated. Thank you!

Hi @EthanCrabb

There’s a great blog post about just this How to Include Files in Netlify Serverless Functions as well as File-based Configuration for Functions docs which talks about this too.

In essence you would use

const verifEmail = require('email_verif.hbs');

in your function, or add something like

inluded_files = "templates/*.hbs"

to your netlify.toml in order to include these files.

1 Like

Hey @coelmay , thanks for your reply.

I’m now getting this error:

Configuration property functions.inluded_files must be an object.

Invalid syntax

  inluded_files = [

My .toml files is as follows:

  inluded_files = ["app/mail/confirm_email/*.hbs"]

  functions = "src"

Have you noticed the typo: inluded_files instead of included_files? I can see @coelmay typed it wrongly, but the docs had the correct version.


My apologies @EthanCrabb for the typo, which I didn’t spot in my original post or your reply. Thanks @hrishikesh for picking it up.

1 Like

Hi @coelmay ,
This works fine now in production, but is broken in development giving me the same error as before.

Configuration property functions.included_files must be an object.

Invalid syntax

  included_files = [

Valid syntax


    external_node_modules = [

Could you share your actual netlify.toml file?

Also what version of CLI are you using?

I’ve just updated to version 6.9.9 and
My .toml currently looks like this:

  included_files = ["app/mail/confirm_email/*.hbs"]

  functions = "src"

  for = "/*"
    Access-Control-Allow-Origin = "https://mysite.com"

This doesn’t seem like it should be a problem. Is it possible for you to setup a minimal test repo with the same problem? It might need some investigation if you’re still seeing it.

Ok, I’ll try set this up by the end of the day. Thanks for your ongoing support!