image: Module causes "__dirname is not defined" error when deploying to Cloudflare Workers

Nuxt3 documents advise you can deploy to Cloudflare Workers. Guide can be found on the Nitro documentation.

The commands wrangler dev and wrangler publish work successfully when @nuxt/image-edge is commented out of the nuxt.config.ts file. However when adding adding it back I receive the following error:

Error: Something went wrong with the request to Cloudflare...
Uncaught ReferenceError: __dirname is not defined
  at worker.js:1:918893
  at worker.js:1:1051834
 [API code: 10021]

Video attached showing it working with @nuxt/image-edge commented out and then adding it back resulting in the error.

https://user-images.githubusercontent.com/10377148/187341690-8c20f653-de1f-4c1a-af90-a0f478850320.mov

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 11
  • Comments: 25 (1 by maintainers)

Most upvoted comments

This was resolved in the first RC with https://github.com/nuxt/image/pull/840 although until the next release, you will need to add the following line to your nuxt.config:

export default defineNuxtConfig({
  image: {
    none: {}
  }
})

Also just experienced this

I’m encountering the same error:

Uncaught ReferenceError: __dirname is not defined
    at worker.js:5680:7030
    at worker.js:17999:4
    at worker.js:18000:3
   [code: 10021]

In nuxt.config.ts, I have set:

image: {
    prismic: {},
  },

Curiously, the error only occurs for our automatic CI deployment via Github actions. Manual deployment from my machine works.

@brpaz I tried on the latest version and using the static provider as you suggested but I get this error Unknown provider: static. Did you run into this?

Yup I just ran into the same. Any word on why this happens?

This probably has something to do with static site generation still not supported.