Git Product home page Git Product logo

Comments (5)

cheapsteak avatar cheapsteak commented on April 27, 2024 1

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.

Kikobeats avatar Kikobeats commented on April 27, 2024 1

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.

cheapsteak avatar cheapsteak commented on April 27, 2024

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.

Kikobeats avatar Kikobeats commented on April 27, 2024

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:

CleanShot 2023-01-18 at 10 23 27@2x

So it's expected to be missing there.

The thing is, if you do the same but using Next.js, __dirname exists:

CleanShot 2023-01-18 at 10 27 24@2x

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.

cheapsteak avatar cheapsteak commented on April 27, 2024

Thanks for clarifying 🙏 does that mean edge-runtime is only meant to be used with NextJS projects?

from edge-runtime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.