Skip to content

Windows: cf build / dev / deploy fail with spawn EFTYPE when delegating to Wrangler #19

Closed

Description

@spike1478

Summary

On Windows, every command that delegates to Wrangler (cf build, cf dev, cf deploy) fails immediately:

├  Build
│  Delegating to Wrangler

┌ Error
│ spawn EFTYPE
└

cf migrate and the API commands work fine. Only the Wrangler delegate path is affected.

Environment

  • Windows 11 (10.0.22631)
  • Node.js v24.13.0
  • cf 1.0.0-beta.5 (global install)
  • wrangler 4.143.0 (local devDependency)
  • Same result in PowerShell 7 and Git Bash
  • Same result with the default bundler and with cf migrate --bundler vite

Steps to reproduce

  1. Take a plain JS Worker with a wrangler.toml (no Vite plugin).
  2. npm i -D wrangler@latest
  3. cf migrate
  4. cf build

Cause

discover-*.mjs resolves the delegate binary as <pkgRoot>/bin/cf-wrangler.js (binary: a("cf-wrangler.js")) and it is then passed straight to child_process.spawn. Windows cannot execute a .js file directly (no shebang support), so Node throws EFTYPE.

Minimal reproduction, run inside the project:

import { spawn, spawnSync } from "node:child_process";
import { resolve } from "node:path";
const js = resolve("node_modules/wrangler/bin/cf-wrangler.js");

spawn(js, ["build"]);                                      // throws: spawn EFTYPE
spawnSync(process.execPath, [js, "build"], { stdio: "inherit" }); // runs

Spawning through process.execPath starts the script normally.

Suggested fix

When the resolved binary ends in .js/.mjs/.cjs, spawn process.execPath with the script path as the first argument, rather than spawning the script itself. That works on every platform, so no Windows-specific branch is needed. The same resolver is used for the other npm delegates (for example cf-vite), so they may be affected too.

Activity

  1. Kanayan-KK commented on Sep 29, 2026

    @Kanayan-KK

    Confirmed with cf 1.0.0-beta.5, Wrangler 4.143.0, and Node.js 24.21.0 on Windows using PowerShell.

    We worked around this using a local pnpm patch. The equivalent source change in packages/cli/src/commands/dev/spawn.ts, inside spawnImpl(), is:

    - const { command, prefixArgs } = parseBinaryToken(binary);
    + const { command, prefixArgs } =
    +   process.platform === "win32" && discovered.impl.ecosystem === "npm"
    +     ? { command: process.execPath, prefixArgs: [binary] }
    +     : parseBinaryToken(binary);

    The existing spawn(command, [...prefixArgs, verb, ...argv], options) call remains unchanged. On Windows, npm delegates are launched through the same Node executable as cf, without enabling shell execution. Other platforms and non-npm delegates retain their existing behavior.

    Applying the workaround to the published package

    We patched the compiled file, not the TypeScript source:

    1. Run:

    2. In the directory printed by pnpm, open dist/spawn-IM_tQldH.mjs and replace this exact fragment:

      let{command:o,prefixArgs:s}=L(a)

      with:

      let{command:o,prefixArgs:s}=process.platform===`win32`&&e.impl.ecosystem===`npm`?{command:process.execPath,prefixArgs:[a]}:L(a)
    3. Save the file and apply the patch:

      pnpm patch-commit "<directory printed by pnpm>"
    4. Retry:

      pnpm exec cf build --mode staging

    The compiled filename and replacement above are specific to cf 1.0.0-beta.5. Commit the generated patch, pnpm patch configuration, and lockfile so subsequent installs retain the workaround.

    Verification

    After applying the patch, the Wrangler-backed build completed successfully:

    ├  Build
    │  Delegating to Wrangler
    ◆  Build complete
    

    A separate subprocess check also verified a delegate path containing spaces, arguments containing spaces and a literal &, and propagation of a non-zero exit code.

    This is a temporary workaround. We have confirmed the Wrangler build path; we have not yet verified cf dev, cloud deployment, or the Vite delegate with this patch.

  2. added theissue type on Sep 29, 2026
  3. added a commit that references this issue on Nov 10, 2026
    cc6831a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions