Skip to content

[Feature] Access remote bindings while building the app #254

@thomas-desmond

Description

@thomas-desmond

Describe the bug

What problem are we solving and why? (This section copied from @irvinebroque)

  • Next.js has SSG (static-site generation) where it takes a route and at build time renders the page to generate the static content, that is then uploaded as part of the app.
  • Sometimes people (ex: @wesbos https://x.com/wesbos/status/1871250855607042293) build routes that depend on data from D1/KV/R2 — ex: put posts in D1 db, render posts from DB
  • This works fine with dynamic routes, but doesn't work with static routes (SSG) (Example SSG route)
  • Why?
  • Because when you run the Next.js build step (via @opennextjs/cloudflare) — this is using getPlatformProxy() behind the scenes to provide access to bindings
  • getPlatformProxy() only supports local dev bindings provided by Miniflare — it does not support --remote
  • This means that if you have a D1 DB you have created, where your data lives and is stored, you can't access it at build time

For Cloudflare Internal Employees:

Steps to reproduce

Steps to Reproduce:

I have a sample repo https://github.com/thomas-desmond/empty-hall-5379 that can be forked but you will need to create your database, see step 2.

  1. Generate a new Next.js application npm create cloudflare@latest my-next-app – --framework=next --experimental (See https://developers.cloudflare.com/workers/frameworks/framework-guides/nextjs/)

  2. Follow the walkthrough to add a D1 database and make a call to that database in your Next.js application. https://developers.cloudflare.com/d1/get-started/ Here is the call I made in my Next.js application page.tsx https://github.com/thomas-desmond/empty-hall-5379/blob/main/src/app/page.tsx

  3. Push the repository to GitHub

  4. Create a new Workers application and connect it to the GitHub repository.

  5. Push changes or trigger a rebuild, and it should fail as previously indicated, displaying an error that states it could not find the database table, despite its existence in your account.

Expected behavior

Workers Assets should be able to access bindings at build time

@opennextjs/cloudflare version

0.3.2

Wrangler version

3.99.0

next info output

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32206
  Available CPU cores: 22
Binaries:
  Node: 20.16.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.2.5 // An outdated version detected (latest is 15.1.4), upgrade is highly recommended!
  eslint-config-next: 14.2.5
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.7.2
Next.js Config:
  output: N/A
 ⚠ An outdated version detected (latest is 15.1.4), upgrade is highly recommended!
   Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
   Read more - https://nextjs.org/docs/messages/opening-an-issue

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions