I dont use `request.clone()` or `response.clone()`
I dont use
request.clone() or response.clone()request.clone()response.clone()platform.env in sveltekit? I've spend too much time in development setupENVIRONMENT in my api endpoint's +server.ts, im so stuckResponse will be different between the two, and any code placed outside of functions will use that tsconfig. So my question is, where do people put things like helpers/utils for functions specific things and not have them exposed as routes?import consumers from 'stream/consumers', miniflare complains:Buffer and Streams API are supported, and I have set node_compat = true in my wrangler.toml. import consumers from 'node:stream/consumers' instead btw.)compatibility_flags = [ "nodejs_compat" ] in addition to node_compat = true?
wrangler 's live reload function seems to break with these nodejs_compat imports. So what I'm seeing is that I can get the code to compile fine when I first run wrangler dev but if I make any code changes at all and wrangler does a live reload, it'll throw that error.nodejs_compat compat flag, not node_compat to import from any node: namespace. But yes, the latest version of wrangler did break live reloads with node: imports, and is being tracked here: https://github.com/cloudflare/workers-sdk/issues/4959nodejs_compat and node_compat flags?node_compat is old and polyfills a bunch of stuff. It's not great, a bit slow, adds to bundle size, and the polyfills aren't perfect. nodejs_compat is Cloudflare's actual Node.js compatibility built right into the workerd runtime. There's some DX pain aroound them both existing right now which I wrote up a bit at https://github.com/cloudflare/workers-sdk/issues/4082nodejs_compat these days, unless you're using something legacy that specifically needs node_compat, like pgnode_compat, only nodejs_compatnode_compat: https://github.com/timothymiller/t4-app/blob/93c8ee3dfcfa181ac7d66c23048cbf7d13648e26/packages/api/wrangler.toml#L4node_compat, not surenodejs_compat, drop node_compat and import from the node: prefix if you can, thoughnode: prefix?node_compat, you might be okay, but then you can't use anything from nodejs_compat. This is unfortunately where the DX starts to really decline, and the crux of my issue at https://github.com/cloudflare/workers-sdk/issues/4082. It's not a great experience.getBindingsProxy, so you could usggest to the Nuxt team that they integrate that, if they aren't already working on itawait response.text(), or await response.json() etc. are common ways to get the body. More here: https://developer.mozilla.org/en-US/docs/Web/API/Response#instance_methods. What does the response contain exactly?workers-sdk repo for examples though: https://github.com/cloudflare/workers-sdk/tree/main/fixtures/pages-functions-app./functions dir) code.wrangler pages functions build ./functions --sourcemap command generates two file index.js & index.js.map which seems something what I need.index.js reveals that it doesn't compile only ./functions code, but also the contents of ./src folder.Compile a folder of Cloudflare Pages Functions into a single Worker./functions into a worker file + sourcemaps and upload the generated worker afterwards?platform.envENVIRONMENTResponsefunctionsfunctionsimport consumers from 'stream/consumers'BufferStreamsnode_compat = truenode_compat = trueimport consumers from 'node:stream/consumers'compatibility_flags = [ "nodejs_compat" ]wrangler devnode_compatnode_compatnode_compatnode_compatnode_compatnode_compatnode_compatnode_compatnode_compatnode:node:node:node:workerdpggetBindingsProxyawait response.text()await response.json()workers-sdk./functions./functions./functionswrangler pages functions build ./functions --sourcemapindex.js.map./srcCompile a folder of Cloudflare Pages Functions into a single Workerexport async function onRequest(context){
console.log('Hello');
return await next();
}✘ [ERROR] Could not resolve "stream/consumers"
src/routes/headlines.ts:13:22:
13 │ import consumers from 'stream/consumers'
╵ ~~~~~~~~~~~~~~~~~~
The package "stream/consumers" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.