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

[Bug?]: Cloudflare adapter fails to inject d1 databases in local environment #1130

Closed
2 tasks done
mr-14 opened this issue Nov 26, 2023 · 3 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@mr-14
Copy link

mr-14 commented Nov 26, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

D1 database defined in vite.config.js does NOT get injected into env when calling createServerData$

Expected behavior 🤔

D1 database defined in vite.config.js should get injected into env when calling createServerData$

Steps to reproduce 🕹

Steps:

  1. Create a bare SolidStart project using the starter
  2. Install solid-start-cloudflare-pages and add d1Databases adapter by following the deploy-a-solid-site guide
import solid from 'solid-start/vite'
import { defineConfig } from 'vite'
import cloudflare from 'solid-start-cloudflare-pages'

export default defineConfig({
	plugins: [ solid({ adapter: cloudflare({ d1Databases: ['my_database'] }) }) ]
})

  1. Edit src/routes/index.jsx to fetch data from d1 databases
import { Title, useRouteData } from 'solid-start'
import { createServerData$ } from 'solid-start/server'

export function routeData() {
	return createServerData$(async (_, { env }) => {
		const sql = 'SELECT * FROM app WHERE id = ?'
		return await env.my_database.prepare(sql).bind('1').first()
	})
}

export default function Home() {
	const data = useRouteData()

	return (
		<main>
			<Title>Test</Title>
			<h1>{data()?.name}</h1>
		</main>
	)
}

I omitted the sql codes to generate the schema. The above code will error out upon calling env.my_database.prepare since env.my_database is undefined.

I also want to mention that the code works on production environment which lead me to believe that the issue has something to do with the adapter.

Thanks!

Context 🔦

I would like to use SolidStart with Cloudflare Pages and would like to use the setup in my local environment to speed up development.

Your environment 🌎

System: Ubuntu 22.04.3 LTS
NODE: v18.16.0
NPM: 9.5.1
solid-start: ^0.3.10
solid-start-cloudflare-pages: ^0.3.10
@mr-14 mr-14 added the bug Something isn't working label Nov 26, 2023
@shripadk
Copy link

shripadk commented Dec 3, 2023

I think this is because solid-start-cloudflare-pages is still using Miniflare 2 instead of Miniflare 3. The __D1_BETA__ prefix was deprecated.

@asterikx
Copy link

asterikx commented Dec 7, 2023

I confirm this bug. d1Databases are not injected, while kvNamespaces work just fine. Is there any workaround for the time being?

As far as I understand solid-start-cloudflare-pages will be replaced by Nitro at some point. However, Nitro is also only using Miniflare 2 at the moment according to #263 (comment).

@ryansolid
Copy link
Member

In setting up for SolidStart's next Beta Phase built on Nitro and Vinxi we are closing all PRs/Issues that will not be merged due to the system changing. If you feel your issue was closed by mistake. Feel free to re-open it after updating/testing against 0.4.x release. Thank you for your patience.

See #1139 for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants