question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using file access for Vercel deployment

See original GitHub issue

Problem

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 theapi 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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
krinoidcommented, Apr 13, 2021

I’ve tried using the zip workaround on Vercel but it doesn’t work due to the zip not being available during build:

image

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.

1reaction
dthyressoncommented, Jan 25, 2021

I’ve chatted with @viperfx is Discord at it was I who referred him to the

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

that will inject the included file into the function zip created by Netlify’s zip-it-and-ship it build process.

zip -ur ${FUNCTIONS_DIST}/graphql.zip ./email/src/templates

It literally adds a file into the archive.

As Vercel notes:

Requiring a file at runtime will not work unless the file is also bundled in the function at the build-phase.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Integration Permissions – Vercel Docs
Retrieves deployments for the hobby or team account. Includes build logs, a list of files and builds, and the file structure for a...
Read more >
How to deploy a Prisma app to Vercel
Hosted PostgreSQL database and a URL from which it can be accessed, e.g. postgresql://username:password@your_postgres_db.cloud.com/db_identifier (you can use ...
Read more >
How to setup Vercel - Next Right Now
Using Vercel, we have access to many staging “deployments”. By default, there is one custom domain per Git Branch, but also one per...
Read more >
Create a Next.js App & Deploy with Vercel - deadbearcode
2. Create Vercel Account · Click Sign Up · Click Continue with Github · It will then prompt you to allow Vercel access...
Read more >
How to include config files when deploying to Vercel
I've never experienced anybody using a private file over private vars. For instance - You make the config file public, but the values...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found