Can't access bound D1 database from Cloudflare Pages

I have a D1 database bound to a Cloudflare Pages and the object context.env.SQLITE is empty. The code works fine locally via mini flare, but when deployed it says that SQLITE.prepare is not a function, well, because the SQLITE object is empty. Any thoughts?

export const home = async (context) => {

  // https://developers.cloudflare.com/d1/changelog
  const db = context.env.SQLITE || context.env.__D1_BETA__SQLITE;
  console.log(JSON.stringify(db));
  const { results } = await db.prepare(`
    select * from posts
  `).all();

// etc.

Have you bound it to both the Production and Preview enviroments?

Yes I have:

and

If you’re using Wrangler 3.5+ then there’s an issue there. Downgrade to 3.4 and it’ll work.

Wrangler was the issue indeed. Worked with V3.4, but not with 3.6 which I was using. Thanks!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.