I’ve been trying to deploy an edge function. I follow the hello_world example from the blog and it works. However, when I try to read environment variable from Netlify, it failed.
5:49:16 PM: Error: file system access error (code 42), id:6fa8a341-0709-4982-ac16-c098093dbe78
at async Object.readFile (deno:deploy/js/02_fs.js:53:12)
at async parseFileAsync (netlify:bundle-combined:940:54)
at async configAsync (netlify:bundle-combined:887:18)
at async netlify:bundle-combined:999:1
5:49:16 PM: Error: file system access error (code 42), id:6e85cc79-b622-4b4c-9115-f87bb3f68c84
at async Object.readFile (deno:deploy/js/02_fs.js:53:12)
at async parseFileAsync (netlify:bundle-combined:940:54)
at async configAsync (netlify:bundle-combined:887:18)
at async netlify:bundle-combined:999:1
5:53:38 PM: Error: file system access error (code 42), id:f5bcaf2b-8b21-4bb4-a90c-fad6b6c7bd67
at async Object.readFile (deno:deploy/js/02_fs.js:53:12)
at async parseFileAsync (netlify:bundle-combined:940:54)
at async configAsync (netlify:bundle-combined:887:18)
at async netlify:bundle-combined:999:1
5:53:38 PM: Error: file system access error (code 42), id:8ce28dae-5880-4510-a3fc-14fd64efb281
at async Object.readFile (deno:deploy/js/02_fs.js:53:12)
at async parseFileAsync (netlify:bundle-combined:940:54)
at async configAsync (netlify:bundle-combined:887:18)
at async netlify:bundle-combined:999:1
Thanks so much for reaching out about this. We will investigate this for you and follow up when we have more information. In the interim, please let us know if anything changes.
Sure! I’d almost guessing that it Edge function is quite “independent” so loading env variable will not work. But would love to know if the Netlify team have recommendations on using environment variable on the edge!
Just hit this same problem, but with a slightly different solution, so documenting here for others:
We also hit issues that Deno.env didn’t work locally in VS Code, just returned all the API keys as undefined, in order to get Deno working locally we also needed to run:
import { configAsync } from 'https://deno.land/x/dotenv/mod.ts';
await configAsync({export: true});
The challenge here is that this works locally, but breaks when deployed to Netlify. As such, we can wrap the configAsync in a try/catch:
try {
// when running locally, we need to call this
// it'll eerror in Netlify prod, but that's okay
await configAsync({export: true});
} catch (err) {
// ignore the error on netlify Prod
}