Skip to content

fix(plugin): warn when package.json is missing type: module - #176

Merged
cpojer merged 1 commit into
mainfrom
fix/vite8-tla-config-loader
May 6, 2026
Merged

cpojer merged 1 commit into
mainfrom
fix/vite8-tla-config-loader

Conversation

@TheAlexLichter

@TheAlexLichter TheAlexLichter commented May 4, 2026 •

Copy link
Copy Markdown
Member

Because of the TLA in the Cloudflare Vite plugin, the user will see an error when not using ESM via type: module. This PR adds a warning + how to fix.

Resolves void-sdk/void#11

Vite 8's default config loader uses CJS require() to load the bundled
config when the project is non-ESM. require() of an ESM graph with TLA
throws ERR_REQUIRE_ASYNC_MODULE, and @cloudflare/vite-plugin (pulled in
by voidPlugin) has a top-level await. Surface this as an actionable
warning at plugin factory time so non-ESM consumers get a clear pointer
before they hit the cryptic Node error. Refs #11.
@cpojer
cpojer merged commit 37f2492 into main May 6, 2026
9 checks passed
@cpojer
cpojer deleted the fix/vite8-tla-config-loader branch May 6, 2026 00:02
cpojer pushed a commit that referenced this pull request Sep 11, 2026
* feat(api): migrate custom-domain cert validation to HTTP-DCV (bump framework)

Switches Cloudflare-for-SaaS custom-hostname certificate DCV from TXT to
HTTP, so users no longer publish rotating `_acme-challenge` TXT records.
Adding a custom domain now needs just two records: the traffic CNAME and
the non-rotating `_cf-custom-hostname` ownership TXT.

The anti-hijack lever stays the DNS-based ownership proof (the security
fix from #154), not the cert-DCV method. The activation gate now keys on
hostname ownership instead of `ssl.method === 'txt'`:

    cfHostname.status === 'active'
      && cfHostname.ssl.status === 'active'
      && !cfHostname.ownership_verification
      && !cfHostname.ownership_verification_http

A wildcard CNAME cannot forge a per-host `_cf-custom-hostname` TXT value,
so ownership stays unsatisfied and `status` never reaches `active`. The
gate is method-agnostic by construction, which keeps legacy `txt`-method
pending domains activatable with no migration.

- cloudflare-api.ts: create body `ssl: { method: 'http', type: 'dv' }`;
  model `ownership_verification_http`; drop the SSL-record poll helper.
- domains.ts: ownership-driven activation gate; remove the create-time
  short-poll and persist `ownership_verification` synchronously; best-
  effort CF + KV cleanup on delete.
- index.ts: 7-day stale-pending janitor — re-checks CF live (skips if
  active, drops orphan rows on 404), claims the row before deleting the
  CF hostname (tolerates 404) and the `domain:` KV entry.
- db.ts: `getPendingDomainsOlderThan` + `deleteDomainIfPending`.
- env.ts: drop the now-dead `CF_HOSTNAME_POLL_*` knobs.
- scripts/dcv-http-spike.ts: oxnode staging spike (HARD ship gate before
  deploy) reproducing the pre-#154 hijack — must pass with --window=86400.
- design-doc 0073 supersedes 0072 (records the two-axis ownership/cert-DCV
  distinction and the wildcard-incompatibility limitation).

Bumps the framework submodule for the matching CLI display change
(#214).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* refactor(api): extract tryActivateDomain helper + add pending-domain queries

Pulls the custom-hostname activation gate, KV routing copy, and
verification-data persistence out of the GET /:id/domains/:domainId
handler into a reusable tryActivateDomain() so the upcoming cron
reconciliation can reuse the exact same security gate. Adds
getPendingDomains() and getPendingDomainsNewerThan() for the cron's
hourly (all-pending) and 30-min fast (young-only) tiers. No behavior
change — existing api-domains tests cover the route 1:1.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(api): auto-activate pending custom domains via cron reconciliation

Adds a reconciliation pass to the scheduled() cron so a custom domain
comes online after the user configures DNS without re-running
\`void domain status\`. Reuses the shared tryActivateDomain gate. Two
tiers via a second cron trigger: the :30 fire reconciles only pending
domains created within RECENT_PENDING_WINDOW_MS (24h) for fast feedback,
while the hourly :00 fire reconciles ALL pending domains — before the
stale-cleanup janitor, so a just-validated domain near the 7-day cutoff
is activated rather than garbage-collected. Per-domain failures are
isolated so one bad CF poll never aborts the batch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* refactor(api): address review on cron reconciliation

- reconcilePendingDomains: replace the per-id getProject loop with a
  single getProjectsByIds(inArray) batch query.
- extract exported FAST_CRON constant shared by the scheduled() branch
  and the tests; log activated/total count.
- hoist the duplicated scheduled() test bindings/ctx into one shared
  definition used by both the janitor and reconciliation describe blocks.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs: record cron-driven custom-domain auto-activation

Adds an addendum to design-doc 0073 and updates meta/operations.md to
document the tiered cron reconciliation (30-min fast tier for recently
added pending domains, hourly fallback that reconciles all pending
before the stale-cleanup janitor) that auto-activates custom domains
after DNS is configured without manual `void domain status` polling.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(api): harden cron domain activation (adversarial-review remediation)

- skip admin-suspended owners in cron reconciliation, matching the 403
  the authenticated status route already returns (usage-suspended owners
  are still reconciled).
- make activation delete-race-safe: tryActivateDomain now claims the row
  via a conditional activateDomainIfPending (UPDATE ... WHERE pending)
  before writing the `domain:` KV entry, and rolls back to pending if the
  KV write fails — so a concurrent `void domain delete` can no longer
  leave an orphan routing entry that resurrects a removed hostname.
- bound CF polling: getPendingDomains/getPendingDomainsNewerThan now take
  a required limit and order oldest-first; the cron caps reconciliation at
  MAX_PENDING_RECONCILE_PER_RUN per run and logs when truncated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(api): revert to self-healing KV-first activation; cap stale cleanup

Per review: the DB-first conditional-claim activation introduced a worse,
non-self-healing failure mode (a crash between the DB flip and the KV
write strands an active row with no route). Revert tryActivateDomain to
the original KV-first order, where a crash leaves the row pending so the
next poll/cron repairs it. The rare delete/activate orphan is accepted
and documented in design-doc 0073 (reconciler + creation quota deferred).
Removes the now-unused activateDomainIfPending helper. Also caps the
stale-pending cleanup janitor (getPendingDomainsOlderThan now takes a
required limit, oldest-first) so a large backlog cannot starve later
hourly maintenance. Keeps the admin-suspended-owner skip and reconcile cap.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(api): retune fast tier to every-2-min burst for first 30 min

Custom-domain auto-activation now polls a freshly added domain every 2
minutes for its first 30 minutes, then falls back to hourly — replacing
the prior once-per-30-min cadence over a 24h window. FAST_CRON becomes
\`*/2 * * * *\` and RECENT_PENDING_WINDOW_MS becomes 30 minutes; the hourly
tier, caps, ordering, suspended-owner skip, and janitor are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(api): re-trigger HTTP DCV via PATCH; activate verified-stale domains (bump framework)

Addresses inline PR review (Cursor Bugbot + Codex) on the cron auto-activation work.

- HTTP-DCV re-trigger (load-bearing): Void's flow is add-domain-first, so the
  CF custom hostname is created with ssl.method:'http' before the CNAME points
  at the managed target. Per CF's Create Custom Hostname API, a PATCH is then
  required to complete HTTP validation; GET-only polling could leave such a
  domain pending until CF deletes it at 7 days. tryActivateDomain() now issues a
  best-effort no-change PATCH (new patchCustomHostname()) that re-triggers DCV
  and resets CF's backoff, gated three ways:
    * options.retriggerDcv — only the HOURLY reconcile tier opts in (not the
      every-2-min fast tier, not the user status route), bounding CF API load so
      a pending burst can't 429 other tenants' hostname ops.
    * wasPending && !gateOk — never PATCH an already-validated/active domain.
    * cf.ssl.method === 'http' — never mutate a legacy txt-DCV pending hostname
      (would discard the user's in-progress validation; breaks no-migration).
- Janitor now activates verified-but-pending stale domains (CF active) instead
  of just skipping, preserving the admin-suspended-owner skip parity and never
  deleting a verified host.
- Stale-cleanup: retry deleteCustomHostname once on a non-404 error after the
  race-safe claim-first delete, then log an explicit ORPHANED warning. Claim-
  first ordering kept; the suggested reorder was declined (reopens a worse race).
- Declined surfacing ownership_verification_http: CF always returns the
  _cf-custom-hostname TXT alongside it, so the user always has an actionable
  challenge; the gate's dual-field check is correct.

Documents the PATCH re-trigger, the hourly-only throttle, the legacy-txt guard,
and the carried-forward >200-backlog forward-progress limitation in 0073.
Bumps framework to #214 (domain add DNS-summary wording fix).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(api): return cname_target from domain status endpoint (bump framework)

Addresses deep-reviewed inline PR comments (codex) on the new commits.

- GET /:id/domains/:domainId now returns `cname_target` (the cname.void.app
  constant, mirroring the add route) so `void domain status` can surface the
  traffic CNAME while the cert is still validating. Additive, backward-compatible
  (no schema change). Bumps framework to #214 for the matching
  CLI display.
- Docs (0073): name the 7-day stale-cleanup janitor as a second actor in the
  already-accepted KV-first activation race (same low-severity, self-healing
  class as the documented `void domain delete` race — the domain is pending/not
  serving, heals via 404 -> re-add). The complete fix remains the deferred
  lock-free reconciler + transition state; a cheap conditional-flip-with-KV-
  rollback was considered and rejected (two-concurrent-activator footgun: it
  could delete a valid route when another activator legitimately won).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore: bump framework submodule to merged #214 (2263964)

Points the framework submodule at the squash-merged #214
on main (HTTP-DCV custom-domain CLI: simplified domain add/status output,
issuing_cert CNAME-hint gating, docs CNAME-target fix). Identical tree to
the prior branch tip; pins a commit reachable from main rather than the
now-merged feature branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
cpojer pushed a commit that referenced this pull request Nov 29, 2026
In a package with `"type": "commonjs"`, which `npm init -y` writes, the
React, Vue, Svelte and Solid starters from `void init` fail in dev,
build and preview:

```
Error: Failed to resolve "@void/svelte/plugin". This package is ESM only but it was tried to load by `require`.
```

In these packages, the starters now use `vite.config.mts`, and all four
work.

An inferred env schema goes to `env.mts` there, because `void env check`
can't load `env.ts` (`Cannot use import statement outside a module`).

When `sourceDir` is set, the inferred schema now goes there, where Void
reads it, instead of to a root file Void ignores.

The warning from #176 to add `"type": "module"` is removed, because it
only showed after the Vite config had loaded as ESM, and those builds
work.
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.

void deploy fails on Vite 8 with ERR_REQUIRE_ASYNC_MODULE

2 participants