question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

🐛 BUG: Unable to use D1 locally

See original GitHub issue

What version of Wrangler are you using?

2.2.1

What operating system are you using?

Mac

Describe the Bug

TEST_DB database is undefined instead of BetaDatabase {} upon checking the context.env.

npx wrangler@2.2.1 pages dev ./public --d1=TEST_DB --local-protocol https --local --persist --log-level debug

console.log(env) { ASSETS: Fetcher {}, TEST_DB: undefined }

npx wrangler@2.2.0 pages dev ./public --d1=TEST_DB --local-protocol https --local --persist --log-level debug

console.log(env) { ASSETS: Fetcher {}, TEST_DB: BetaDatabase {} }

Creation of the database is okay ./wrangler/state/d1/TEST_DB.sqlite3 but the only problem is the binding.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:2
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
tom-shermancommented, Nov 21, 2022

This appears to be a bug in wrangler meaning the --d1 flag doesn’t work correctly.

It looks like you can only add D1 bindings in wrangler.toml. So to fix this right now you can add the following code to your wrangler.toml (obviously replacing the values that are relevant for your DB)

[[ d1_databases ]]
binding = "MY_DATABASE"
database_name = "my_database"
database_id = "azertyazerty"

You also then need to REMOVE the --d1 flag you’re passing to wrangler pages dev and also add the --persist flag`.

However this is apparently a temporary workaround as wrangler.toml isn’t supposed to work with cloudlfare pages.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BUG: Unable to use D1 binding with local pages dev ... - GitHub
For Windows, wrangler@d1 seems to be broken entirely. If I run npx wrangler@d1 pages dev .\public\ I get the same out as the...
Read more >
Gitlab Runner not able to resolve Gitlab URL - Kubernetes ...
I'm using microk8s and a gitlab self hosted (11.7.5) in local for development. Added hostAliases for gitlab-runner deployment to point to my ...
Read more >
Fix list for Rational ClearCase - IBM
This document contains a complete listing of releases, refreshes, fix packs and interim fixes sorted by version for IBM® Rational ClearCase.
Read more >
Verify errorcode = 20 : unable to get local issuer certificate
There is a bug entry for this OpenSSL problem, but nobody from the OpenSSL ... You can fetch it from Verisign's Use of...
Read more >
Common HAProxy Errors - DigitalOcean
This tutorial series explains how to troubleshoot and fix some of the most common errors that you may encounter when using the HAProxy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found