i reran npx wrangler types to generate a

i reran npx wrangler types to generate a new worker-configuration.d.ts, and instead of doing this: interface Env { ... } it did: declare namespace Cloudflare { interface Env { ... } } interface Env extends Cloudflare.Env {} and now my env doesn't work anywhere... (context.cloudflare.env doesn't have any of my types on it) Has anyone run into this or know how to fix it? (this is in a remix app, but I've updated to wrangler 4 and been using it fine for a bit...)
5 Replies
zsmooth
zsmoothOP2mo ago
I tracked this down to @cloudflare/workers-types being installed as a peer dep, and the Cloudflare.Env referencing the empty one in that. I found a workaround by adding import "./worker-configuration.d.ts" at the top of the root file using the Env and it fixed the resolution.
matthewlsessions
Thanks for this info! However, this work around kind of defeats the purpose of having the types specified in the ts config though. To be totally frank, I just downgraded the worker-type package to 4.0.0 as a work around. I'll wait for the SDK team to flush the new cloudflare namespace definition
zsmooth
zsmoothOP2mo ago
It actually would be nice if they could publish a version of workers-types that’s empty, so we could pin to that version with npm overrides, to get around the issue of it getting installed as a peer dep
echoes221
echoes2213w ago
OMG, thank you so much - just tracked this down to sentry-cloudflare installing this as an optional dependency. Was driving me nuts!
Jökull Sólberg
Has anyone been able to have worker-configuration.d.ts take "type precedence" over peerDependency installed @cloudflare/workers-type? I'm having the same issue, I had to set auto-install-peers=false in .npmrc but pnpm still reports peer dependency errors, and adding overrides is annoying. Wondering what the general vision for wrangler types is... (because, sidenote, peerDependencyMeta with optional: true, has some open bugs, at least in pnpm) One offender, actually from cloudflare, is workers-ai-provider, that doesn't even have @cloudflare/workers-types as a peerDependency but a "straight up" dependency - presumably this would need to be updated? https://github.com/cloudflare/ai/blob/main/packages/workers-ai-provider/package.json

Did you find this page helpful?