Next.js Discord

Discord Forum

How to include files in serverles functions

Unanswered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
hello to all,

I have a problem right now with a certain function and I can't understand why, nor find a solution (Nextjs v14.x.x).

I have a function for sending mails that has marked the "use server" to run only in server mode. The thing is that this function uses nunjucks to generate the HTML that will be the body of the mail, and these templates are in src/templates/templates/email/..., it happens that when executing the saving of a resource this executes a server function to store and then this executes my function of sending mail; however, in this execution it crashes with the error that it does not find the directory src/temolates and much less the njk files. On the other hand, for testing purposes I called the function with test data from a path /api/test/route.ts and the template files are there correctly.

What am I missing to make it work with the server function, I already tried the following things without success:

* creating the vercel.json file with the functions and the includeFiles.
* adding to the next.config.js the path in the experimental.outputFileTracingIncludes key.
* adding a Copy of files to the webpack through the next.config.js file.

0 Replies