Vercel read from function Next.js
Unanswered
Sloth bear posted this in #help-forum
Sloth bearOP
I have a function from Next.js that sends an email using a liquid template.
Locally works, and on Digital Ocean (probably because on the way of the container is built)
But on Vercel, is failing with the error
I tried doing on the
To read from
Locally works, and on Digital Ocean (probably because on the way of the container is built)
const emailsDirectory = path.resolve(process.cwd(), "src/pages/api/email/templates");
const liquidEngine = new Liquid({
root: [emailsDirectory],
extname: ".liquid",
});
const emailFile = readFileSync(path.join(emailsDirectory, `${templateName}.liquid`), {
encoding: "utf8",
});But on Vercel, is failing with the error
Error: ENOENT: no such file or directory, open '/var/task/src/pages/api/email/templates/sign-in.liquid'"I tried doing on the
next.config.js experimental: {
outputFileTracingIncludes: {
"/api/email-template": ["./src/pages/api/email/templates/**"],
},
},To read from
/api/email-template but the output is not working as expected as it is not generating that folder.8 Replies
You can't access the file system within a serverless environment.
readFileSync will not work.Sloth bearOP
So, what is the solution???
Sloth bearOP
The alternative solution as I need to access those files 😦
If you only need to read files, you can store them in your
public directory, but if you need to read and write you need to store them externally afaik.Sloth bearOP
So, what is the outputFileTracingIncludes, that is a solution given on this file https://vercel.com/guides/loading-static-file-nextjs-api-route?
You tagged this as an Edge Function related issue, the Edge runtime does not have access to Node.js API like
fsThat link is using the Node.js runtime
Sloth bearOP
Sorry, wrong tag them... Which tag should I use?