image icon indicating copy to clipboard operation
image copied to clipboard

IPX Error: ReferenceError: __dirname is not defined in ES module scope

Open Alex--C opened this issue 3 years ago • 0 comments

I'm using nuxt/image-edge with nuxt3-edge with the default local IPX provider. Locally (macOS), everything works great (with both dev + build mode). However, when trying to run the application on a linux machine, I get the error from the title when requesting an image:

IPX Error: ReferenceError: __dirname is not defined in ES module scope

Both machines are using the same node version (16.16 LTS). I'm not able to figure out where this error is coming from - any hints? Not using any custom configs for nuxt/image, simply installed the dependency and added the module to both modules and buildModules in my nuxt.config.ts.

Edit: Was able to get a stack trace:

ReferenceError: __dirname is not defined in ES module scope
    at file:///.output/server/chunks/index.mjs:1271:32
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at async file:///.output/server/chunks/nitro/node-server.mjs:17476:21
    at async _handleRequest (file:///.output/server/chunks/nitro/node-server.mjs:17546:28)
    at async file:///.output/server/chunks/nitro/node-server.mjs:17612:5
    at async file:///.output/server/chunks/nitro/node-server.mjs:8280:19
    at async Server.nodeHandler (file:///.output/server/chunks/nitro/node-server.mjs:8226:7)

Which corresponds to the following code from sharp's libvips.js:

const vendorPath = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, platform());

Alex--C avatar Aug 05 '22 12:08 Alex--C