Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for miniflare on windows #25599

Open
ryuapp opened this issue Sep 12, 2024 · 3 comments
Open

Support for miniflare on windows #25599

ryuapp opened this issue Sep 12, 2024 · 3 comments
Labels
bug Something isn't working correctly windows Related to Windows platform

Comments

@ryuapp
Copy link
Contributor

ryuapp commented Sep 12, 2024

Miniflare is a simulator for developing and testing Cloudflare Workers, powered by workerd.
This library is used by many frameworks as Cloudflare adapter.
e.g.) SvelteKit, Astro, HonoX

Currently, the example written in README does not work either.

PS miniflare> deno --version
deno 2.0.0-rc.2+0a4a8c7 (canary, release, x86_64-pc-windows-msvc)
v8 12.9.202.13-rusty
typescript 5.5.2

miniflare> me mini.ts

import { Miniflare } from "npm:miniflare";

// Create a new Miniflare instance, starting a workerd server
const mf = new Miniflare({
        script: `addEventListener("fetch", (event) => {
    event.respondWith(new Response("Hello Miniflare!"));
  })`,
});

// Send a request to the workerd server, the host is ignored
const response = await mf.dispatchFetch("http://localhost:8787/");
console.log(await response.text()); // Hello Miniflare!

// Cleanup Miniflare, shutting down the workerd server
await mf.dispose();

PS miniflare> deno -A mini.ts
error: Uncaught (in promise) TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at Function.from (<anonymous>)
    at Object.<anonymous> (file:///C:/Users/xxxx/AppData/Local/deno/npm/registry.npmjs.org/miniflare/3.20240821.1/dist/src/index.js:6744:64)
    at Object.<anonymous> (file:///C:/Users/xxxx/AppData/Local/deno/npm/registry.npmjs.org/miniflare/3.20240821.1/dist/src/index.js:10197:4)
    at Module._compile (node:module:735:34)
    at Object.Module._extensions..js (node:module:756:11)
    at Module.load (node:module:655:32)
    at Function.Module._load (node:module:523:13)
    at Module.require (node:module:674:19)
    at require (node:module:800:16)
    at file:///C:/Users/xxxx/AppData/Local/deno/npm/registry.npmjs.org/miniflare/3.20240821.1/dist/src/index.js:3:13

Related: #25513

@lucacasonato
Copy link
Member

It works for me using both node_modules and npm: specifiers and a global module directory:

$ npm install miniflare
$ cat main.ts
import { Miniflare } from "miniflare";

// Create a new Miniflare instance, starting a workerd server
const mf = new Miniflare({
	script: `addEventListener("fetch", (event) => {
    event.respondWith(new Response("Hello Miniflare!"));
  })`,
});

// Send a request to the workerd server, the host is ignored
const response = await mf.dispatchFetch("http://localhost:8787/");
console.log(await response.text()); // Hello Miniflare!

// Cleanup Miniflare, shutting down the workerd server
await mf.dispose();

$ deno -V
deno 1.46.3
$ deno run -A main.ts
Hello Miniflare!
$ cat main.ts
import { Miniflare } from "npm:miniflare";

// Create a new Miniflare instance, starting a workerd server
const mf = new Miniflare({
	script: `addEventListener("fetch", (event) => {
    event.respondWith(new Response("Hello Miniflare!"));
  })`,
});

// Send a request to the workerd server, the host is ignored
const response = await mf.dispatchFetch("http://localhost:8787/");
console.log(await response.text()); // Hello Miniflare!

// Cleanup Miniflare, shutting down the workerd server
await mf.dispose();

$ deno -V
deno 1.46.3
$ deno run -A main.ts
Hello Miniflare!

Maybe this only happens on Windows?

@ryuapp
Copy link
Contributor Author

ryuapp commented Sep 12, 2024

Maybe this only happens on Windows?

I guess so. There were no errors when I ran it on WSL.

@nathanwhit nathanwhit changed the title Support for miniflare Support for miniflare on windows Sep 12, 2024
@nathanwhit nathanwhit added bug Something isn't working correctly windows Related to Windows platform labels Sep 12, 2024
@nathanwhit
Copy link
Member

Confirmed it reproduces on windows. The immediate issue is #25604, but supporting this will also require fixing #23524

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly windows Related to Windows platform
Projects
None yet
Development

No branches or pull requests

3 participants