New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Failed to instantiate edge runtime.fig:load:flatten", "__dirname is not defined" #225
Comments
looks like I was missing the step of adding apologies for the noise |
actually sorry this is now working locally with function logs https://vercel.com/cheapsteak1/lskjdf/DTvY4XUMnwcJoGJU6vkq2rALiNcw/functions showing
|
Hello, the global __dirname is missing at Edge Runtime because it's a Node.js API and the Edge Runtime effort is to cover WinterCG API: So it's expected to be missing there. The thing is, if you do the same but using Next.js, That's because Next.js is extending Edge Runtime API surface, adding |
Thanks for clarifying 🙏 does that mean edge-runtime is only meant to be used with NextJS projects? |
Not really: You can extend Edge Runtime to add whatever you need: const { EdgeRuntime } = require('edge-runtime')
const runtime = new EdgeRuntime({
extend: context => {
context.__dirname = __dirname
return context
}
})
Promise.resolve().then(async () => {
const result = await runtime.evaluate('__dirname')
console.log(result)
}) Take a look to https://edge-runtime.vercel.app/getting-started#usage 🙂 |
Bug Report
Current behavior
Created a blank project to test middleware
Server starts up fine
but upon accessing localhost:3000, the page returns "This Edge Function has crashed", and the console logs
Expected behavior/code
The middleware function to run instead of returning page crash
Possible solution
Additional context/screenshots
Repro by running
npm run ddev
Archive.zip
I don't believe this is a duplicate of #209 since I've tried running with node@16.19.0 and also downgrading to a version of vercel cli that was using edge-runtime@1.1.0 and received the same errors
The text was updated successfully, but these errors were encountered: