sourcemap support is on the docket for the API? That's pretty much the only bit of moving to v3 that's got me bummed, the logging leaves a lot to be desiredworkerd, you'll need to wrap your worker with something that returns un-source-mapped stack traces as JSON using the MF-Experimental-Error-Stack header: https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/templates/middleware/middleware-miniflare3-json-error.ts. Wrangler will do this automatically.workerd at some point. wrangler.toml parsing and passing bindings in the config- it's less "magic", but for me it seems easier to debugunstable_dev() API (https://developers.cloudflare.com/workers/wrangler/api/) at some point soon, which will allow you to use your wrangler.toml file, but customise as required in JavaScript too. wrangler dev, right? If there is I can save myself the pain of manually putting together the esbuild watch -> MF reload script.wrangler dev session in each worker's directory, they should auto-magically connect. We're considering eventually moving to a Docker Compose style solution, where running wrangler dev automatically starts up all required services though.
toml (I had just added the placement table and had services below it, so services was interpreted as a key on placement)console.logs appear when running via the API, but they are appearing via wrangler dev. I have log: new Log(LogLevel.VERBOSE), in my options and verbose: true,, is there something else I'm missing?workerd's logging. Wrangler actually uses the DevTools inspector protocol for logging instead.workers array but the contents of /scripts/ can change during dev, and this way the latest script is used for each request. is this an ok approach?Miniflare instance across requests. Do you know the possible values for req.params.name ahead of time? Could you cache mf values for each name in a Map<string, Miniflare>? You'll probably also want to copy the headers across from queryRes to res, and might consider streaming the body instead of buffering it. See the writeResponse function in Miniflare's own code for this: https://github.com/cloudflare/miniflare/blob/6984a7f7a35a5b91dea3bb62d657818ca3cb52a2/packages/miniflare/src/index.ts#L307-L354../scripts will change quite a lot during development, e.g../scripts/<worker_name> folders created/deleted./scripts/<worker_name>/index.js updatedmf instances, but is there a way to invalidate the cache in either of these scenarios?const promise = cache.get(key)?.dispose(); cache.delete(key); await promise; should invalidate itsetOptions() yourself with updatesunstable_dev? I'm not seeing anything show up in DevToolsawait response.body?.pipeTo(Writable.toWeb(initialStream))
workerd/jsg/util.c++:276: error: e = kj/compat/tls.c++:215: failed: TLS peer's certificate is not trusted; reason = unable to get local issuer certificateworkerd runtime as deployed on Cloudflare's network to run your code, instead of reimplementing workers runtime APIs in Node.js. This significantly increases the fidelity of local mode. However, because we're now running your code in a separate process, some of Miniflare v2's features that relied on passing JavaScript references from inside the workers sandbox to other Node.js code are now much more difficult to implement. Namely, the Jest/Vitest testing environments and the Miniflare#get*() methods. We're actively working on bringing the testing environments back, and are planning to add back deprecated support for getBindings()/getKVNamespace()/getR2Bucket()/getCaches()/getDurableObjectNamespace() whilst we figure out a better way to support framework dev servers. https://github.com/cloudflare/miniflare/discussions/588 has some more discussion around this.wrangler.toml. That responsibility has been delgated to Wrangler's unstable_dev() API (https://developers.cloudflare.com/workers/wrangler/api/#unstable_dev). We're working on stabilising this at the moment, and the API is likely to change significantly in the future. For now, I'd recommend translating your wrangler.toml to Miniflare API options (https://github.com/cloudflare/miniflare/blob/tre/packages/miniflare/README.md). To fix the specific error you're seeing, you'll likely need to add modules: true, but you may also need to configure kvNamespaces/r2Buckets/etc if you're using those.npx miniflare fail on my mac ( via devDependencies also not working)yarn also fail, not thing work on my machine. maybe only me sourcemapMF-Experimental-Error-Stackunstable_dev()unstable_dev()esbuildtomlplacementplacementconsole.logslog: new Log(LogLevel.VERBOSE),verbose: true,workers/scripts/app.use('/:name/*', async (req, res) => {
const mf = new Miniflare({
scriptPath: `./scripts/${req.params.name}/index.js`,
bindings: process.env,
})
const url = `http://localhost:8787${req.originalUrl}`
const queryRes = await mf.dispatchFetch(url, {
method: req.method,
headers: req.headers,
body: req.body,
})
res.send(await queryRes.text())
await mf.dispose()
})Miniflarereq.params.namemfmfMap<string, Miniflare>queryReswriteResponse./scripts./scripts/<worker_name>./scripts/<worker_name>/index.jsconst promise = cache.get(key)?.dispose(); cache.delete(key); await promise;setOptions()await response.body?.pipeTo(Writable.toWeb(initialStream))mounts: {
books: {
// here I define name, scriptPath, modules, compatDate, compatFlags, bindings
}
}Worker "core:user:example"'s binding "BOOKS" refers to a service "core:user:books", but no such service is definedserviceBindings.books = req => {
const smf = new Miniflare(<same options as mount config>)
return smf.dispatchFetch(req)
}workerd/jsg/util.c++:276: error: e = kj/compat/tls.c++:215: failed: TLS peer's certificate is not trusted; reason = unable to get local issuer certificateserviceBindings[bindingName] = req => {
const smf = new Miniflare(options)
return smf.dispatchFetch(req)
}Miniflare#get*()getBindings()getKVNamespace()getR2Bucket()getCaches()getDurableObjectNamespace()modules: truekvNamespacesr2Bucketsnpx miniflaredevDependencies36 verbose stack Error: could not determine executable to run
36 verbose stack at getBinFromManifest (/Users/katopz/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/libnpmexec/lib/get-bin-from-manifest.js:17:23)
36 verbose stack at exec (/Users/katopz/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/libnpmexec/lib/index.js:185:15)
36 verbose stack at async module.exports (/Users/katopz/.nvm/versions/node/v18.16.0/lib/node_modules/npm/lib/cli.js:134:5)
37 verbose pkgid miniflare@3.20230628.0Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at Socket._writeGeneric (node:net:930:11)
at Socket._write (node:net:942:8)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at Socket.Writable.write (node:internal/streams/writable:337:10)
at Runtime.updateConfig (/nexus/node_modules/miniflare/src/runtime/index.ts:132:26)
at async Miniflare.#assembleAndUpdateConfig (/nexus/node_modules/miniflare/src/index.ts:790:23)
at async Miniflare.#init (/nexus/node_modules/miniflare/src/index.ts:472:5) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
}