File system access in Edge Functions

Currently, it is not possible to read or write files from the file system in Edge Functions. We are evaluating the use cases for potential solutions and are working on making this functionality available in one or another form.

If there is a specific use case that you are thinking of or you have a feature request around this topic, please let us know!

If you landed here because you received this error locally when using the Netlify CLI in a next.js project, please update the CLI and the npm package @netlify/plugin-nextjs to the latest versions.

We’ve got error when we try to run netlify dev in local machine.
Our use case is

  • Use Nextjs with middleware feature
  • Run netlify dev and we’ve got this error.

I’m assume that when we run netlify dev it call some script from netlify.app then script try to read/write files from my local, Am I correct ?
Could you help for this issue ?

I have this same issue, I have a Next.js app and have serverless functions in netlify/functions that serve as API endpoints for the frontend.

Previously I was able to test the whole thing locally using netlify dev, now I am getting this error.

I just updated to netlify-cli@13.1.1, the error persists since then.

Hi @hubagaspar91 and @chonlatit.tpit , I’ve tried reproducing this error using a new Next.js app with a middleware.ts file, and my site worked as expected locally using netlify dev. Is it possible for you to share a minimal reproduction case where you see this error?

Also, if possible, can you share more about the error that you’re getting? Logs (if they don’t contain any private information) are very helpful in debugging these types of issues.

Thank you!

Hi @ivaaan , we are experiencing the similar issue w/ same use case as mentioned by @hubagaspar91 when we upgraded to 13.1.1. When running on local dev machine we get this error. We do not have any serverless functions that attempt to read or write to the local file system. We downgraded our CLI to get it working again for now. I’ve uploaded a screenshot of the the traced section in netlify middleware file on the local machine in the exception trace and included the error output from the build log if that helps.

◈ Loaded edge function netlify dev handler
event - compiled client and server successfully in 981 ms (253 modules)
[next-dev] Error: Reading or writing files with Edge Functions is not supported yet. Visit https://ntl.fyi/edge-functions-filesystem to learn more and tell us about your use cases for file system access.
    at Object.errorCallback (https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/deno-fs.ts:4:9)
    at exists (file:///Users/******/Documents/GitHub/******//.netlify/edge-functions/next-dev/index.js:25:16)
    at handler (file:///Users/******/Documents/GitHub/******//.netlify/edge-functions/next-dev/index.js:48:13)
    at https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/function_chain.ts:381:15
    at https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/util/named_wrapper.ts:19:24
    at nf_req_01GV4V9D1BAQE02EMM135SP8WZ (https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/util/named_wrapper.ts:12:68)
    at callWithNamedWrapper (https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/util/named_wrapper.ts:19:10)
    at FunctionChain.runFunction (https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/function_chain.ts:379:28)
    at FunctionChain.run (https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/function_chain.ts:296:31)
    at handleRequest (https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/handler.ts:73:34)
[next-dev] Error: Reading or writing files with Edge Functions is not supported yet. Visit https://ntl.fyi/edge-functions-filesystem to learn more and tell us about your use cases for file system access.
    at Object.errorCallback (https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/deno-fs.ts:4:9)
    at exists (file:///Users/******/Documents/GitHub/******//.netlify/edge-functions/next-dev/index.js:25:16)
    at handler (file:///Users/******/Documents/GitHub/******//.netlify/edge-functions/next-dev/index.js:48:13)
    at https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/function_chain.ts:381:15
    at https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/util/named_wrapper.ts:19:24
    at nf_req_01GV4V9D2HW7MBFYVTX5C2A6T2 (https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/util/named_wrapper.ts:12:68)
    at callWithNamedWrapper (https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/util/named_wrapper.ts:19:10)
    at FunctionChain.runFunction (https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/function_chain.ts:379:28)
    at FunctionChain.run (https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/function_chain.ts:296:31)
    at handleRequest (https://64071f3033a1800007cc20f8--edge.netlify.app/bootstrap/handler.ts:73:34)
wait  - compiling...
event - compiled client and server successfully in 138 ms (253 modules)

1 Like

Hi @okey , thank you for the extra info! We’ve released the version 13.1.2 of the netlify-cli to fix this regression. If you still see it happening, please let us know in this thread!

1 Like

I have a usecase where I’m using netlify edge function to generate an OG image on the fly. Using the netlify example: og-edge/custom-font.tsx at main · ascorbic/og-edge · GitHub.

However, I’d like to load the custom font that I use on my site rather then one hosted on Google Font or some CDN. I understand that’s not possible right now, but is there a workaround?

Hiya @jonathanyeong :wave:t6: , welcome back to the forums!

You could consider including the font file in your Edge function code, rather than loading it from your site? You can try base64 to encode the font file and include it as a string in your function code then use the font-face rule to define the font.

1 Like

Thanks for the warm welcome back! Interesting option, I’ll give it a try!

In my project I would like to keep multiple versions of web app, and let the client to choose between them by sending a version number along with the request.

Let’s say, client wants to get v1.2 app, they send a request to /index.html?v=1.2. Edge function was meant to go through the list of deployed versions, where each version is represented by a file: v1.0.0.html, v1.1.0.html, v1.2.0.html, v1.2.1.html. It would then return the latest version that match requested version, in our case it is v1.2.1.html.

Is this a valid case for using file system, even with reduced functionality?

@maksim.kalinin, is it not possible to upload all those HTML files to the Netlify CDN and serve the correct file based on the request URL? I am not 100% convinced yet that this needs a file system, but happy to discuss further.

Yes, that is exactly what I want to do.
However, I want it to be a bit “smart” in a way that it would find the most recent version that satisfies the query. For example, if client requested v1.2 and server has both v1.2.0 and v1.2.1, it should return v1.2.1.

I can even imagine it being solved not by the filesystem, but by simply having all the assets ids in memory. For example, by accessing hypothetical context.deploy.assets from within the edge function.

sure, you could absolutely code that up in an edge function! Something like:

  • during build, look for all versions on disk that will be deployed to our CDN
  • put that list into the edge function, including aliases, so that:
  1. a request for “v1.2.x” is served specific-latest version /1.2.3
  2. a request for “v.1.3.x” is served specific-latest vrsion /1.3.0
  3. a request for “latest” is aliased to /1.3.0 since that is the latest.

Your edge function would see the request and either fetch the content, or better, return an http 302 redirect to the appropriate version that is served from our CDN. I suggett an HTTP 302 so that e.g. /latest can change in the future to a newer version :slight_smile:

1 Like