Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thomas-desmond opened this issue Jan 14, 2025 · 2 comments
Open

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

thomas-desmond opened this issue Jan 14, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@thomas-desmond
Copy link

thomas-desmond commented Jan 14, 2025

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

@thomas-desmond thomas-desmond added bug Something isn't working triage labels Jan 14, 2025
@vicb
Copy link
Contributor

vicb commented Jan 15, 2025

We are looking at that internally (https://jira.cfdata.org/browse/RM-21062)

Maybe one way to workaround for now would be to import your DB before building, something like:

wrangler d1 export --remote
wrangler d1 execute --local --file

@vicb vicb added enhancement New feature or request and removed bug Something isn't working triage labels Jan 15, 2025
@vicb vicb changed the title [BUG] Unable to build SSG application on Cloudflare when a binding is introduced. [Feature] Access remote bindings while building the app Jan 15, 2025
@wesbos
Copy link
Contributor

wesbos commented Jan 15, 2025

a few more thoughts + approaches from @irvinebroque wesbos/wesbos#406

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

3 participants