cloudflare: root entry eagerly imports `wrangler`, so `d1`/`r2`/`kvCache` cannot load without a Wrangler install
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- cloud
Research direction
Start with dist/index.mjs, where the issue identifies the eager Wrangler import and its use in sandbox(). Reproduce the reported d1/r2/kvCache import with Wrangler absent, then check whether the root entry can load without it. Done means those descriptors are importable without Wrangler while the optional sandbox behavior remains available.
Written by the indexing model from the issue text.
Description
Summary
@emdash-cms/cloudflare's root entry eagerly imports wrangler at module load:
// dist/index.mjs, line 1
import { unstable_readConfig } from "wrangler";
The only use is inside sandbox():
function sandbox() {
const environment = process.env.CLOUDFLARE_ENV;
if (!unstable_readConfig(environment ? { env: environment } : {}, { hideWarnings: true })
.worker_loaders?.some((loader) => loader.binding === "LOADER")) {
console.warn("[emdash] Sandboxed plugins are disabled because wrangler.jsonc has no LOADER Worker Loader binding. ...");
return;
}
return "@emdash-cms/cloudflare/sandbox";
}
So a project that never calls sandbox() — and therefore never needs a Wrangler
config at all — still cannot import d1 / r2 / kvCache unless the wrangler
package is installed.
Impact
Deploying through a non-Wrangler tool (Alchemy's Cloudflare.Website.Astro, in
our case) means no wrangler.jsonc and no reason to install wrangler. Importing
the config helpers then fails at config-load time:
ERR_MODULE_NOT_FOUND: Cannot find package 'wrangler' imported from
node_modules/@emdash-cms/cloudflare/dist/index.mjs
Nothing in that path calls sandbox(); the failure is purely the eager import.
Reproduce
// astro.config.mjs
import { d1, r2, kvCache } from "@emdash-cms/cloudflare";
with wrangler absent from the dependency tree (e.g. autoInstallPeers: false,
or a pnpm workspace where the peer is not otherwise pulled in).
Note the peer declaration alone is not the issue — the package is declared as a
required peer, so pnpm installs it. The problem is that a deploy-tool-specific
dependency is reachable from the root entry at all: any resolution that does not
install the peer makes the whole config unloadable.
Suggested fix
Make the Wrangler access lazy, so the root entry is usable without wrangler:
async function sandbox() {
const { unstable_readConfig } = await import("wrangler");
...
}
(sandbox() is already async-shaped/optional in practice — it returns a module
path or undefined.) Alternatively move sandbox() behind its own subpath
(e.g. @emdash-cms/cloudflare/sandbox-config) so importing the descriptors does
not pull Wrangler in. Making wrangler an optional peer would match either
change.
Environment
emdash / @emdash-cms/cloudflare |
1.2.0 |
astro |
7.3.5 |
| deploy | Alchemy Cloudflare.Website.Astro (no Wrangler config) |
This looks adjacent to #3639 (Cloudflare config only read from Wrangler files)
and #2841 (Wrangler config not auto-discovered), but is narrower: it is not about
reading a Wrangler config, it is about the package being unimportable when
Wrangler is absent.
- Dominant language
- TypeScript
- Stars
- 13.4k
- Forks
- 1.3k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 571
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from emdash-cms/emdash
-
bot:bug bot:needs-attention
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
emdash-cms/emdash#4110 · 2 comments ·
Maintainers usually reply within 1 day
-
bot:bug bot:needs-attention bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
emdash-cms/emdash#3992 · 2 comments ·
Maintainers usually reply within 1 day
-
bot:bug bot:needs-attention
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
emdash-cms/emdash#3972 · 2 comments ·
Maintainers usually reply within 1 day
-
plugin-forms: textarea in FormEmbed renders with whitespace as its initial valuePossibly taken @Cloud-Xero claimed this 10 days ago. Openarea/plugins bot:bug bot:human-owned bug priority/low
Difficulty 1/5 Under an hour Newbie friendliness 88/100
emdash-cms/emdash#3935 · 4 comments · 2 assignees ·
Maintainers usually reply within 1 day
-
bot:needs-attention bot:task
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
emdash-cms/emdash#3821 · 1 comment ·
Maintainers usually reply within 1 day
All issues in emdash-cms/emdash
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Koenkk/zigbee-herdsman-converters#13540 ·
Maintainers usually reply within 1 day
-
check:passed streams:add
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
iptv-org/iptv#55821 · 1 comment ·
Maintainers usually reply within 1 day
-
area/busola/ux
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
kyma-project/busola#5442 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vercel-labs/wterm#246 ·
Maintainers usually reply within 1 day