Nuxt3 deploy fails - __dirname is not defined at worker.mjs

Trying to deploy a Nuxt3 project via Github and it fails, log at the end.


export default defineNuxtConfig({
ssr: true,
target: ‘static’,
modules: [
image: {
provider: ‘ipx’,
/* Other configs omitted */

Forcing use of node v16

Attempting node version ‘v16’ from .nvmrc
Downloading and installing node v16.18.0…
Now using node v16.18.0 (npm v8.19.2)

Build log

nuxt build
Nuxi 3.0.0-rc.12
Nuxt 3.0.0-rc.12 with Nitro 0.6.0
:information_source: Using Tailwind CSS from ~/assets/css/tailwind.css
:information_source: Client built in 3543ms
:information_source: Building server…
:heavy_check_mark: Server built in 1643ms
:heavy_check_mark: Generated public .output/public
:information_source: Building Nitro Server (preset: cloudflare_pages)
:heavy_check_mark: Nitro server built
└─ functions/path.js (542 kB) (162 kB gzip)
Σ Total size: 542 kB (162 kB gzip)
:heavy_check_mark: You can preview this build using npx wrangler pages dev .output/public
:heavy_check_mark: You can deploy this build using npx wrangler pages publish .output/public
:construction: ‘wrangler pages ’ is a beta command. Please report any issues
Compiled Worker successfully.
Validating asset output directory
Deploying your site to Cloudflare’s global network…
Success: Assets published!
Error: Failed to publish your Function. Got error: Uncaught ReferenceError: __dirname is not defined at worker.mjs:5414:18