Skip to content

fix: add directory to wrangler assets config for static export#221

Open
arifpro wants to merge 1 commit intocloudflare:mainfrom
arifpro:fix/219-wrangler-assets-directory
Open

fix: add directory to wrangler assets config for static export#221
arifpro wants to merge 1 commit intocloudflare:mainfrom
arifpro:fix/219-wrangler-assets-directory

Conversation

@arifpro
Copy link

@arifpro arifpro commented Mar 2, 2026

When using output: 'export' in next.config.ts, wrangler 4.69.0 requires
the assets config to include a directory property. This fix:

  • Detects output mode from next.config during deploy
  • Adds directory: 'export' to wrangler assets config for static export
  • Skips images binding for static export (not needed since images are
    pre-optimized at build time)

Fixes #219

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 7, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@221

commit: 37fdce4

@james-elicx
Copy link
Collaborator

/bigbonk review this pr please

Copy link
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix — the core idea (detect output: 'export' and add directory to the wrangler assets config) is correct and addresses the issue. A few things need attention before this can merge.

Summary of issues

  1. Hardcoded "export" directory may not match the actual build output. The directory name is hardcoded, but the static export system uses a caller-provided outDir — if that ever changes (or a user overrides it), the wrangler config would point to the wrong directory. At minimum this should have a comment explaining the assumption, or better, derive the value from where the build actually writes to.

  2. main and worker entry are still generated for static export. When output: 'export', there's no Worker script — it's a static site. The generated wrangler.jsonc still includes "main": "./worker/index.ts" and getFilesToGenerate still creates worker/index.ts. These are unnecessary (and potentially confusing) for a static-only deployment. This is a larger concern but worth flagging.

  3. No tests for the new behavior. The generateWranglerConfig test suite should cover the static export case: verify directory: "export" is present in assets, verify the images binding is omitted, and verify the non-export case is unchanged. The existing tests all use detectProject which returns output: "", so the new code paths are untested.

  4. getOutputMode is async but detectProject is sync. The PR mutates info.output after construction (info.output = await getOutputMode(root)), which is a bit awkward. It works, but it means detectProject returns incomplete data that must be patched up by the caller. Consider either making detectProject async or documenting this limitation clearly.

@ask-bonk
Copy link
Contributor

ask-bonk bot commented Mar 7, 2026

Review submitted. Here's a summary of the feedback I posted on PR #221:

Requested changes with 4 inline comments:

  1. Hardcoded "export" directory (deploy.ts:377) — The directory name is hardcoded as "export" but the static export build system takes outDir as a parameter. If the build output directory ever changes, the wrangler config would point to the wrong place. Needs at minimum a comment, ideally a shared constant.

  2. Worker entry still generated for static export (deploy.ts:373) — The main field and worker/index.ts are still generated even when output: 'export'. A pure static site doesn't need a Worker script, and including one could cause wrangler to fail or confuse users.

  3. getOutputMode does unnecessary work (deploy.ts:227) — It calls resolveNextConfig (which evaluates async redirects/rewrites/headers and probes webpack) just to read a single output string. Suggested reading directly from loadNextConfig instead.

  4. Post-construction mutation of info.output (deploy.ts:1027) — The detectProject function returns output: "" and the caller must patch it afterward, which is fragile. Any code running between construction and the patch sees the wrong value.

Additionally noted the lack of tests — the new generateWranglerConfig behavior for static export (directory field in assets, omitted images binding) has no test coverage.

github run

@arifpro arifpro force-pushed the fix/219-wrangler-assets-directory branch from 8b390b2 to a29b027 Compare March 8, 2026 05:28
When `output: "export"` is set in next.config, wrangler requires the
`assets.directory` property. This reads the output mode via loadNextConfig
(avoiding unnecessary resolveNextConfig overhead) and adjusts the
generated wrangler.jsonc:

- Adds `directory` to assets config via shared STATIC_EXPORT_DIR constant
- Omits `main` (no Worker script needed for static sites)
- Omits `images` binding (images pre-optimized at build time)
- Omits `assets.binding` (no Worker to expose assets to)
- Skips worker/index.ts generation in getFilesToGenerate

Closes cloudflare#219

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@arifpro arifpro force-pushed the fix/219-wrangler-assets-directory branch from a29b027 to 814b37a Compare March 8, 2026 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vinext deploy fails with wrangler error: assets config missing required directory property when using output: "export" in next.config.ts

2 participants