Comments (5)
actually sorry this is now working locally with vercel dev
but not working when deployed
function logs https://vercel.com/cheapsteak1/lskjdf/DTvY4XUMnwcJoGJU6vkq2rALiNcw/functions showing
[GET] /
13:56:48:09
ReferenceError: __dirname is not defined
at worker.js:21:23819
at worker.js:21:23861
at worker.js:14:28
at worker.js:21:24002
at worker.js:14:28
at worker.js:21:24667
at worker.js:14:28
at worker.js:21:25045
at worker.js:14:28
at worker.js:23:103
[GET] /favicon.ico
13:56:35:43
ReferenceError: __dirname is not defined
at node_modules/next/dist/compiled/ua-parser-js/ua-parser.js:10:16756
at node_modules/next/dist/compiled/ua-parser-js/ua-parser.js:10:16885
at node_modules/next/dist/server/web/spec-extension/user-agent.js:8:41
at node_modules/next/server.js:6:0
at middleware.js:4:15
at middleware:middleware.js:1:17
from edge-runtime.
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 🙂
from edge-runtime.
looks like I was missing the step of adding next
as a dependency 🤦
(I thought I didn't need it since I thought I saw somewhere that middleware and edge functions were framwork agnostic)
apologies for the noise
from edge-runtime.
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, __dirname
exists:
That's because Next.js is extending Edge Runtime API surface, adding __dirname
polyfill to be possible to cover more user cases.
from edge-runtime.
Thanks for clarifying 🙏 does that mean edge-runtime is only meant to be used with NextJS projects?
from edge-runtime.
Related Issues (20)
- `import.meta.url` is `undefined` HOT 1
- `@edge-runtime/types` should declare global types for `fetch`, `File` etc HOT 3
- Allow customisation of `ResponseCookie` encoding HOT 2
- Expose cookie serialization functions. HOT 1
- Include a key in process.versions for detecting edge runtime HOT 2
- Support `has` in ResponseCookies
- Set-Cookie headers are merged when using `fetch` HOT 6
- Primitives: event-target-shim causes issues w/ edge-runtime running on top of node HOT 3
- drop node16 support
- Proxying primitive instances return anonymous `toString()` return functions
- Why cannot my `fetch` API work in edge function? HOT 4
- 🙏`fetch` api doesn't work in edge function HOT 4
- Which functions and APIs advance the value returned by `Date.now`? HOT 3
- Polyfill for btoa inconsistent with WebApi / Node HOT 5
- drop node18 support
- Response.redirect() fails to parse some URLs in production which parse successfully in local runtime HOT 2
- `@edge-runtime/node-utils` can't start example server from docs using `primitives` (node v18.18.2) Headers2 is not a constructor HOT 1
- Secure Cookies can't be deleted from Responses
- CompressionStream / DecompressionStream support?
- failing on buffer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from edge-runtime.