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 ?
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.
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)
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!
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?
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.
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:
a request for “v1.2.x” is served specific-latest version /1.2.3
a request for “v.1.3.x” is served specific-latest vrsion /1.3.0
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
I’m trying to inject some data (in my case some additional configuration loaded via an external system) into the local dev environment via a build plugin. In real builds I will likely accomplish this by actually rewriting / injecting into the built code, but locally in dev mode, I was hoping to just be able to inject it some other way.
So far I have not been able to figure out any way to get that data into the environment other than using @netlify/blobs. However in order for that to work, the function itself must import and use @netlify/blobs first or else the import within my helper file does not end up in the import map.
Interestingly, once I import (and use) @netlify/blobs in the edge function file, all the regular filesystem related stuff is in fact imported and works just fine, because I see you are also using the local filesystem to mock the blob stuff during dev mode.
Any way to inject some additional data into the local deno dev environment would work, but I figured the local filesystem was an easy workaround until I hit this issue… What if it was enabled only during local dev, and threw some kind of warning?
I believe it used to work in the past, but was then removed as it did not work in production. What’s the point of having a feature in dev that won’t work online?
As for injecting is concerned, it’s possible to inject Edge Functions in dev using build plugins. Did that not work?
I’m attempting to use a build plugin to inject additional code into the existing functions and edge functions that the user already has - either via direct authoring, or using an integration (ex: this astro adapter)
In prod (or when calling netlify build locally, I can use the build hooks to assess and modify the generated code. This only happens once so no problem.
During netlify dev, the dev loop means that build process is happening over and over as the user changes their code - yet there is no hook provided to be able to continually modify the built code as it gets updated.
At best, there would be more hooks to let me know the files have changed, which files, etc… At worst, I would at least have file-system access so I could try to get to these files anyway. However that said I also discovered that build plugins don’t appear to have the ability to create any kind of long-running background processes - so I could not watch the files and rerun.
Happy to dig in further with you and explain the use case.