Skip to content

Secret not found in secret store in local mode #9369

@joelmiles

Description

@joelmiles

What versions & operating system are you using?

wrangler 4.16.1, node 22.14.0, Windows 11

Please provide a link to a minimal reproduction

No response

Describe the Bug

I have a secret in my local secrets store as seen here:

wrangler secrets-store secret list 24c5810008074d388f81b2a34e98448f

🔐 Listing secrets... (store-id: 24c5810008074d388f81b2a34e98448f, page: 1, per-page: 10)
┌─────────────────────────┬──────────────────────────────────┬─────────┬────────┬─────────┬───────────────────────┬───────────────────────┐
│ Name                    │ ID                               │ Comment │ Scopes │ Status  │ Created               │ Modified              │
├─────────────────────────┼──────────────────────────────────┼─────────┼────────┼─────────┼───────────────────────┼───────────────────────┤
│ contentful-access-token │ adaf5e903ec44232a9f64431dca6ddae │         │        │ active  │ 5/26/2025, 5:27:16 PM │ 5/26/2025, 5:27:16 PM │
├─────────────────────────┼──────────────────────────────────┼─────────┼────────┼─────────┼───────────────────────┼───────────────────────┤
│ contentful-space-id     │ 9a7df593b71848d49728e3e932144ab7 │         │        │ active  │ 5/26/2025, 5:27:16 PM │ 5/26/2025, 5:27:16 PM │
└─────────────────────────┴──────────────────────────────────┴─────────┴────────┴─────────┴───────────────────────┴───────────────────────┘

and wrangler.jsonc contains:

"secrets_store_secrets": [
	{
		"binding": "CONTENTFUL_SPACE_ID",
		"store_id": "24c5810008074d388f81b2a34e98448f",
		"secret_name": "contentful-space-id"
	},
	{
		"binding": "CONTENTFUL_ACCESS_TOKEN",
		"store_id": "24c5810008074d388f81b2a34e98448f",
		"secret_name": "contentful-access-token"
	}
]

However, when accessing the secret in code like this:

import { getCloudflareContext } from "@opennextjs/cloudflare";
const context = await getCloudflareContext({ async: true });
const CONTENTFUL_ACCESS_TOKEN = await context.env.CONTENTFUL_ACCESS_TOKEN.get();

When building via opennextjs-cloudflare build, I receive this error message: Error: Secret "contentful-access-token" not found which seems to be emitted from here:

throw new Error(`Secret "${this.env.secret_name}" not found`);

Is this a bug, or am I accessing the secret incorrectly?

Please provide any relevant error logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    error-messagingImproving user facing error messages

    Type

    No fields configured for Bug.

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions