Skip to content

Commit

Permalink
chore: error if d1 bindings used with no-bundle (#1955)
Browse files Browse the repository at this point in the history
While in beta, you cannot use D1 bindings without bundling your worker as these are added in through a facade which gets bypassed when using the no-bundle option.

This will be removed once the bindings are no longer needing to be added using a shim.
  • Loading branch information
cameron-robey committed Sep 29, 2022
1 parent 27784fb commit b6dd07a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/kind-crews-sing.md
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

chore: error if d1 bindings used with `no-bundle`

While in beta, you cannot use D1 bindings without bundling your worker as these are added in through a facade which gets bypassed when using the `no-bundle` option.
10 changes: 10 additions & 0 deletions packages/wrangler/src/dev/dev.tsx
Expand Up @@ -245,6 +245,16 @@ function DevSession(props: DevSessionProps) {
);
}

// If we are using d1 bindings, and are not bundling the worker
// we should error here as the d1 shim won't be added
if (Array.isArray(betaD1Shims) && betaD1Shims.length > 0 && props.noBundle) {
handleError(
new Error(
"While in beta, you cannot use D1 bindings without bundling your worker. Please remove `no_bundle` from your wrangler.toml file or remove the `--no-bundle` flag to access D1 bindings."
)
);
}

const workerDefinitions = useDevRegistry(
props.name,
props.bindings.services,
Expand Down
13 changes: 13 additions & 0 deletions packages/wrangler/src/publish.ts
Expand Up @@ -390,6 +390,19 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
);
}

// If we are using d1 bindings, and are not bundling the worker
// we should error here as the d1 shim won't be added
const betaD1Shims = identifyD1BindingsAsBeta(config.d1_databases);
if (
Array.isArray(betaD1Shims) &&
betaD1Shims.length > 0 &&
props.noBundle
) {
throw new Error(
"While in beta, you cannot use D1 bindings without bundling your worker. Please remove `no_bundle` from your wrangler.toml file or remove the `--no-bundle` flag to access D1 bindings."
);
}

const {
modules,
resolvedEntryPointPath,
Expand Down

0 comments on commit b6dd07a

Please sign in to comment.