Using file access for Vercel deployment
See original GitHub issueProblem
When using libraries that need file access, there is no supported way to do this with Vercel + Redwood. Typically the use case here is templating libraries that initialize with a template directory of files, which the serverless functions need access to.
Attempts to make this work
Using the following vercel config option - https://vercel.com/knowledge/how-can-i-use-files-in-serverless-functions. By including the following vercel.json config
{
"functions": {
"api/src/functions/*.js": {
"includeFiles": "api/src/templates/**"
}
}
}
However, you get an error. I’ve tried many different patterns but they all seem to fail with the following message
Error: The pattern "api/src/functions/*.js" defined in
functionsdoesn't match any Serverless Functions inside the
api directory. Learn More: https://vercel.link/unmatched-function-pattern
The following repo can be used to reproduce the issue - https://github.com/viperfx/redwood-fs-vercel-bug
Vercel’s response
After getting in touch with Vercel, and providing them with a repo to reproduce the issue, eventually, I got a reply from an engineer.
Checking this issue with one of our engineers, Vercel can’t support “includeFiles” with Redwood at the moment. The way Redwood is configured is that it will bundle the dependencies together and all required files at build-time. Requiring a file at runtime will not work unless the file is also bundled in the function at the build-phase.
Checking the Redwood documentation and code-base, it appears you can’t run this code either on AWS Lambda or Netlify, as it is a framework limitation.
References
Known workaround for Netlify - https://community.redwoodjs.com/t/how-can-i-read-and-bundle-a-non-js-or-ts-file-from-my-netlify-function/1021/11
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (7 by maintainers)
I’ve tried using the
zip
workaround on Vercel but it doesn’t work due to thezip
not being available during build:I can imagine that one can create a node script to do this during build, but I’m exploring other potential solutions/workarounds for my case.
I’ve chatted with @viperfx is Discord at it was I who referred him to the
that will inject the included file into the function zip created by Netlify’s zip-it-and-ship it build process.
It literally adds a file into the archive.
As Vercel notes:
And that’s what that workaround does in the build plugin … and what would have to be solved in a general way during any deploy.
But, right now I don’t have a solution in mind.