Cannot read properties of r2

I am trying to interact with r2 bucket from a worker. But I get this error
[wrangler:err] TypeError: Cannot read properties of undefined (reading 'get')
[wrangler:err] TypeError: Cannot read properties of undefined (reading 'get')
Yes, I have already bind the bucket inside wrangler.toml file
9 Replies
Hello, I’m Allie!
Do you have a repo I can take a look at?
Yashu
YashuOP8mo ago
Sorry the repo is private. Let me try to create a bare-minimum repo.
Yashu
YashuOP8mo ago
GitHub
GitHub - mittalyashu/cf-worker-r2-repo
Contribute to mittalyashu/cf-worker-r2-repo development by creating an account on GitHub.
Hello, I’m Allie!
Try this:
name = "private-worker"
main = "src/index.ts"
compatibility_date = "2024-04-05"

r2_buckets = [
{ binding = 'JS_VARIABLE', bucket_name = 'private-r2-dev' }
]

[vars]
ENVIRONMENT = "dev"


[env.production]
vars = { ENVIRONMENT = "production" }

routes = [
{ pattern = "api.example.com", custom_domain = true }
]

r2_buckets = [
{ binding = 'JS_VARIABLE', bucket_name = 'private-r2-prod' }
]
name = "private-worker"
main = "src/index.ts"
compatibility_date = "2024-04-05"

r2_buckets = [
{ binding = 'JS_VARIABLE', bucket_name = 'private-r2-dev' }
]

[vars]
ENVIRONMENT = "dev"


[env.production]
vars = { ENVIRONMENT = "production" }

routes = [
{ pattern = "api.example.com", custom_domain = true }
]

r2_buckets = [
{ binding = 'JS_VARIABLE', bucket_name = 'private-r2-prod' }
]
Yashu
YashuOP8mo ago
I also tried looking about this in the docs, but couldn't find it documented anywhere. When we run a worker in dev mode. I know that for KV a local instance is created, but what about r2? Thanks this worked, I no longer get that error 🙏
Hello, I’m Allie!
Yes, in the .wrangler folder
Yashu
YashuOP8mo ago
Thanks Can you please, share me the docs link. Where I can learn more about the specification order for wrangler.toml to work properly if I add more things?
Hello, I’m Allie!
That's just TOML being weird: https://toml.io/en/v1.0.0 If it makes it easier, you can also use wrangler.json
Yashu
YashuOP8mo ago
:lul:
Want results from more Discord servers?
Add your server